@@ -17,19 +17,13 @@ export class SqliteAdapter {
1717
1818 adapter ! : SqlMigrationAwareDriverAdapterFactory ;
1919 async init ( ) {
20+ console . log ( "CWD: " + process . cwd ( ) ) ;
21+ console . log ( "DB: " + this . databasePath ) ;
22+
2023 const libsql = await this . adapter . connect ( ) ;
2124
2225 // this is used to test the upgrade path
23- if ( process . env . RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_0 ) {
24- throw new Error ( "this is disabled" ) ;
25- await libsql . executeScript ( await readFile ( dist_resolve (
26- "../prisma-20250406/migrations/" + INIT_0_0 + "/migration.sql"
27- ) , "utf8" ) ) ;
28- } else if ( process . env . RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_1 ) {
29- await libsql . executeScript ( await readFile ( dist_resolve (
30- "../prisma/migrations/" + INIT_0_1 + "/migration.sql"
31- ) , "utf8" ) ) ;
32- } else if ( process . env . RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_2 ) {
26+ if ( process . env . RUN_FIRST_MWS_DB_SETUP_FOR_TESTING_0_2 ) {
3327 await libsql . executeScript ( await readFile ( dist_resolve (
3428 "../prisma/migrations/" + INIT_0_2 + "/migration.sql"
3529 ) , "utf8" ) ) ;
@@ -62,8 +56,12 @@ export class SqliteAdapter {
6256 argTypes : [ ] ,
6357 } ) . then ( e => e . rows . map ( e => e [ 0 ] as string ) )
6458 ) ;
59+ const oldVersion =
60+ applied_migrations . has ( INIT_0_0 ) ? "0.0" :
61+ applied_migrations . has ( INIT_0_1 ) ? "0.1" :
62+ undefined ;
6563
66- if ( applied_migrations . has ( INIT_0_0 ) ) {
64+ if ( oldVersion ) {
6765 console . log ( [
6866 "=======================================================================================" ,
6967 "The database you are trying to open is from a previous version of MWS." ,
@@ -72,20 +70,19 @@ export class SqliteAdapter {
7270 "wikis you want to keep by opening them and downloading them as single-file" ,
7371 "wikis by clicking on the cloud status icon and then 'save snapshot for offline use'." ,
7472 "" ,
73+ "CWD: " + process . cwd ( ) ,
74+ "DB: " + this . databasePath ,
75+ "" ,
7576 "To return to a usable version of this wiki, you may run " ,
7677 "" ,
77- "npm install @tiddlywiki/mws@0.0" ,
78+ "npm install @tiddlywiki/mws@" + oldVersion ,
79+ "" ,
80+ "To prevent data loss the program will now exit." ,
7881 "=======================================================================================" ,
7982 ] . join ( "\n" ) )
80- await this . checkMigrationsTable ( libsql , hasExisting && ! hasMigrationsTable , applied_migrations , "prisma-20250406" , INIT_0_0 ) ;
81- console . log ( "Your database is updated to the final version for 0.0.x" ) ;
82- console . log ( "This database is for a previous version of MWS. We will now exit to prevent data loss." ) ;
83- console . log ( "=======================================================================================" ) ;
8483 process . exit ( 1 ) ;
85- // } else if (!applied_migrations.size || applied_migrations.has(INIT_0_1)) {
86- // await this.checkMigrationsTable(libsql, hasExisting && !hasMigrationsTable, applied_migrations, "prisma", INIT_0_1);
8784 } else if ( ! applied_migrations . size || applied_migrations . has ( INIT_0_2 ) ) {
88- await this . checkMigrationsTable ( libsql , hasExisting && ! hasMigrationsTable , applied_migrations , "prisma" , INIT_0_2 ) ;
85+ await this . checkMigrationsTable ( libsql , applied_migrations , "prisma/migrations" ) ;
8986 } else if ( this . isDevMode ) {
9087 console . log ( [
9188 "===============================================================" ,
@@ -137,13 +134,13 @@ export class SqliteAdapter {
137134 // prisma/migrations/20250508171144_init/migration.sql
138135 async checkMigrationsTable (
139136 libsql : SqlDriverAdapter ,
140- migrateExisting : boolean ,
141137 applied_migrations : Set < string > ,
142- prismaFolder : string ,
143- initMigration : string
138+ prismaMigrationsFolder : string
144139 ) {
145140
146- const migrations = await readdir ( dist_resolve ( "../" + prismaFolder + "/migrations" ) ) ;
141+ const migrations = await readdir ( dist_resolve ( "../" + prismaMigrationsFolder ) ) ;
142+ // the folder names are the iso digit string
143+ // NOTE: Of all the insanities, numbers are sorted as strings!
147144 migrations . sort ( ) ;
148145
149146 const new_migrations = migrations . filter ( m => ! applied_migrations . has ( m ) && m !== "migration_lock.toml" ) ;
@@ -156,17 +153,13 @@ export class SqliteAdapter {
156153 console . log ( "New migrations found" , new_migrations ) ;
157154
158155 for ( const migration of new_migrations ) {
159- const migration_path = dist_resolve ( `../${ prismaFolder } /migrations /${ migration } /migration.sql` ) ;
156+ const migration_path = dist_resolve ( `../${ prismaMigrationsFolder } /${ migration } /migration.sql` ) ;
160157 if ( ! existsSync ( migration_path ) ) continue ;
161158
162159 const fileContent = await readFile ( migration_path , 'utf-8' ) ;
163- // this is the hard-coded name of the first migration.
164- if ( migrateExisting && migration === initMigration ) {
165- console . log ( "Existing migration" , migration , "is already applied" ) ;
166- } else {
167- console . log ( "Applying migration" , migration ) ;
168- await libsql . executeScript ( fileContent ) ;
169- }
160+
161+ console . log ( "Applying migration" , migration ) ;
162+ await libsql . executeScript ( fileContent ) ;
170163
171164 await libsql . executeRaw ( InsertStatement ( "_prisma_migrations" , [
172165 {
0 commit comments