File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " Loopndroll" ,
3- "version" : " 1.1.0 " ,
3+ "version" : " 1.1.1 " ,
44 "private" : true ,
55 "type" : " module" ,
66 "packageManager" : " pnpm@10.33.0" ,
Original file line number Diff line number Diff line change @@ -705,6 +705,29 @@ function nowIsoString() {
705705 return new Date ( ) . toISOString ( ) ;
706706}
707707
708+ function shouldIgnoreMigrationStatementError (
709+ sqlite : Database ,
710+ statement : string ,
711+ error : unknown ,
712+ ) {
713+ const message = error instanceof Error ? error . message : String ( error ) ;
714+ if ( ! message . toLowerCase ( ) . includes ( "duplicate column name:" ) ) {
715+ return false ;
716+ }
717+
718+ const match = / ^ \s * a l t e r \s + t a b l e \s + ( \w + ) \s + a d d \s + c o l u m n \s + ( \w + ) / i. exec ( statement ) ;
719+ if ( ! match ) {
720+ return false ;
721+ }
722+
723+ const [ , tableName , columnName ] = match ;
724+ const rows = sqlite . query ( `pragma table_info(${ tableName } )` ) . all ( ) as Array < {
725+ name ?: string ;
726+ } > ;
727+
728+ return rows . some ( ( row ) => row . name === columnName ) ;
729+ }
730+
708731export function applyAppMigrations (
709732 sqlite : Database ,
710733 migrations : readonly AppMigration [ ] = appMigrations ,
@@ -727,7 +750,15 @@ export function applyAppMigrations(
727750
728751 const applyMigration = sqlite . transaction ( ( migration : AppMigration ) => {
729752 for ( const statement of migration . statements ) {
730- sqlite . exec ( statement ) ;
753+ try {
754+ sqlite . exec ( statement ) ;
755+ } catch ( error ) {
756+ if ( shouldIgnoreMigrationStatementError ( sqlite , statement , error ) ) {
757+ continue ;
758+ }
759+
760+ throw error ;
761+ }
731762 }
732763
733764 insertAppliedMigration . run ( migration . id , migration . name , nowIsoString ( ) ) ;
Original file line number Diff line number Diff line change @@ -2476,6 +2476,22 @@ function configureDatabase(db) {
24762476 }
24772477}
24782478
2479+ function shouldIgnoreMigrationStatementError(db, statement, error) {
2480+ const message = error instanceof Error ? error.message : String(error);
2481+ if (!message.toLowerCase().includes("duplicate column name:")) {
2482+ return false;
2483+ }
2484+
2485+ const match = /^\\s*alter\\s+table\\s+(\\w+)\\s+add\\s+column\\s+(\\w+)/i.exec(statement);
2486+ if (!match) {
2487+ return false;
2488+ }
2489+
2490+ const [, tableName, columnName] = match;
2491+ const rows = db.query(\`pragma table_info(\${tableName})\`).all();
2492+ return rows.some((row) => row.name === columnName);
2493+ }
2494+
24792495function applyMigrations(db) {
24802496 db.exec(\`create table if not exists schema_migrations (
24812497 id integer primary key,
@@ -2490,7 +2506,15 @@ function applyMigrations(db) {
24902506 );
24912507 const applyMigration = db.transaction((migration) => {
24922508 for (const statement of migration.statements) {
2493- db.exec(statement);
2509+ try {
2510+ db.exec(statement);
2511+ } catch (error) {
2512+ if (shouldIgnoreMigrationStatementError(db, statement, error)) {
2513+ continue;
2514+ }
2515+
2516+ throw error;
2517+ }
24942518 }
24952519
24962520 insertMigration.run(migration.id, migration.name, nowIsoString());
You can’t perform that action at this time.
0 commit comments