Skip to content

Commit

Permalink
fix(channel-web): down mig drop all msg_ tables (#5452)
Browse files Browse the repository at this point in the history
Co-authored-by: Laurent Leclerc Poulin <laurentlp@users.noreply.github.com>
  • Loading branch information
samuelmasse and laurentlp committed Sep 15, 2021
1 parent 839a9b3 commit 6f03d1c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
13 changes: 8 additions & 5 deletions modules/channel-web/src/messaging-migration/down-pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ export class MessagingPostgresDownMigrator extends MessagingDownMigrator {
protected async cleanup() {
await super.cleanup()

await this.trx.raw('DROP TABLE msg_messages CASCADE')
await this.trx.raw('DROP TABLE msg_conversations CASCADE')
await this.trx.raw('DROP TABLE msg_users CASCADE')
await this.trx.raw('DROP TABLE msg_clients CASCADE')
await this.trx.raw('DROP TABLE msg_providers CASCADE')
const tables = await this.trx('pg_catalog.pg_tables')
.select('tablename')
.andWhere('tablename', 'like', 'msg_%')

for (const table of tables) {
await this.trx.raw(`DROP TABLE ${table.tablename} CASCADE`)
}

await this.trx.raw('DROP EXTENSION pgcrypto;')
}

Expand Down
25 changes: 15 additions & 10 deletions modules/channel-web/src/messaging-migration/down-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,26 @@ export class MessagingSqliteDownMigrator extends MessagingDownMigrator {
await super.cleanup()

if (this.bp.database.isLite) {
const tables = await this.trx('sqlite_master')
.select('name')
.where({ type: 'table' })
.andWhere('name', 'like', 'msg_%')

await this.trx.raw('PRAGMA foreign_keys = OFF;')

await this.trx.schema.dropTable('msg_messages')
await this.trx.schema.dropTable('msg_conversations')
await this.trx.schema.dropTable('msg_users')
await this.trx.schema.dropTable('msg_clients')
await this.trx.schema.dropTable('msg_providers')
for (const table of tables) {
await this.trx.schema.dropTable(table.name)
}

await this.trx.raw('PRAGMA foreign_keys = ON;')
} else {
await this.trx.raw('DROP TABLE msg_messages CASCADE')
await this.trx.raw('DROP TABLE msg_conversations CASCADE')
await this.trx.raw('DROP TABLE msg_users CASCADE')
await this.trx.raw('DROP TABLE msg_clients CASCADE')
await this.trx.raw('DROP TABLE msg_providers CASCADE')
const tables = await this.trx('pg_catalog.pg_tables')
.select('tablename')
.andWhere('tablename', 'like', 'msg_%')

for (const table of tables) {
await this.trx.raw(`DROP TABLE ${table.tablename} CASCADE`)
}
}
}

Expand Down

0 comments on commit 6f03d1c

Please sign in to comment.