Skip to content

Commit

Permalink
fix: fix delete table
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Nov 7, 2024
1 parent 7e18506 commit cdc544d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/persistence/src/table/table.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,21 @@ export class TableRepository implements ITableRepository {
.where((eb) => eb.or([eb.eb("table_id", "=", table.id.value), eb.eb("foreign_table_id", "=", table.id.value)]))
.execute()

await trx
.deleteFrom("undb_dashboard_table_id_mapping")
.where((eb) => eb.eb("table_id", "=", table.id.value))
.execute()

await trx
.deleteFrom("undb_attachment_mapping")
.where((eb) => eb.eb("table_id", "=", table.id.value))
.execute()

await trx
.deleteFrom("undb_webhook")
.where((eb) => eb.eb("table_id", "=", table.id.value))
.execute()

await trx
.deleteFrom("undb_table")
.where((eb) => eb.eb("id", "=", table.id.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class UnderlyingTableSpecVisitor implements ITableSpecVisitor {
const field = schema.field
if (field.isOwner) {
const joinTable = new JoinTable(this.table.table, field)
const query = this.qb.schema.dropTable(joinTable.getTableName()).compile()
const query = this.qb.schema.dropTable(joinTable.getTableName()).ifExists().compile()
this.addSql(query)
}
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class UnderlyingTableService {
async delete(table: TableDo) {
const t = new UnderlyingTable(table)
const trx = getCurrentTransaction()
await trx.schema.dropTable(t.name).execute()
await trx.schema.dropTable(t.name).ifExists().execute()
const referenceFields = table.schema.getReferenceFields()
for (const field of referenceFields) {
const joinTable = new JoinTable(table, field)
Expand Down

0 comments on commit cdc544d

Please sign in to comment.