Skip to content

Commit

Permalink
refactor: change dropAllTables implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Feb 11, 2024
1 parent e038c67 commit f84a710
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
14 changes: 5 additions & 9 deletions src/dialects/base_sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,12 @@ export abstract class BaseSqliteDialect implements DialectContract {
* Drop all tables inside the database
*/
async dropAllTables() {
await this.client.rawQuery('PRAGMA writable_schema = 1;')
await this.client
.knexQuery()
.delete()
.from('sqlite_master')
.whereIn('type', ['table', 'index', 'trigger'])
.whereNotIn('name', this.config.wipe?.ignoreTables || [])
const tables = await this.getAllTables()
const promises = tables
.filter((table) => !this.config.wipe?.ignoreTables?.includes(table))
.map((table) => this.client.rawQuery(`DROP TABLE ${table};`))

await this.client.rawQuery('PRAGMA writable_schema = 0;')
await this.client.rawQuery('VACUUM;')
await Promise.all(promises)
}

/**
Expand Down
6 changes: 0 additions & 6 deletions test-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ export function getConfig(): ConnectionConfig {
},
useNullAsDefault: true,
debug: !!process.env.DEBUG,
pool: {
afterCreate(connection, done) {
connection.unsafeMode(true)
done()
},
},
}
case 'mysql':
return {
Expand Down

0 comments on commit f84a710

Please sign in to comment.