File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ const fingersCrossedMode = command === 'fingers-crossed';
1818const yoloMode = command === 'yolo' ;
1919const noMigrationMode = ! fingersCrossedMode && ! yoloMode ;
2020
21+ const DISABLE_FOREIGN_KEYS_SQL = "PRAGMA foreign_keys=OFF" ;
22+
2123/**
2224 * @typedef MigrationState
2325 * @property {string[] } files
@@ -41,16 +43,18 @@ const selectTablesFromDatabase = async (/**@type {LibSQLClient}*/client) => {
4143
4244const dropAllDatabaseTables = async ( /**@type {LibSQLClient }*/ client ) => {
4345 const tableNames = await selectTablesFromDatabase ( client ) ;
44- if ( tableNames . length === 1 ) return console . log ( 'No tables to drop...' ) ;
46+ if ( tableNames . length === 0 ) return console . log ( 'No tables to drop...' ) ;
47+
4548 for ( const tableName of tableNames ) {
4649 try {
4750 console . warn ( 'Dropping table:\x1b[31m' , tableName , '\x1b[0m...' ) ;
48- await client . execute ( ` drop table '${ tableName } '`) ;
51+ await client . executeMultiple ( ` ${ DISABLE_FOREIGN_KEYS_SQL } ; drop table '${ tableName } '; `) ;
4952 } catch ( error ) {
5053 console . error ( 'FAILED TO DROP TABLE' ) ;
5154 throw error ;
5255 }
5356 }
57+
5458}
5559const upstreamMigrationStatePath = ( /**@type {string }*/ databaseId ) => `scripts/out/${ databaseId } -migrations.upstream-ref.json` ;
5660const upstreamMigrationStateExists = ( /**@type {string }*/ databaseId ) => fs . existsSync ( upstreamMigrationStatePath ( databaseId ) ) ;
You can’t perform that action at this time.
0 commit comments