From cdc544dccb77ddf793160e580fed9f9c39b9a3b7 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Thu, 7 Nov 2024 20:18:31 +0800 Subject: [PATCH] fix: fix delete table --- .../persistence/src/table/table.repository.ts | 15 +++++++++++++++ .../underlying/underlying-table-spec.visitor.ts | 2 +- .../src/underlying/underlying-table.service.ts | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/persistence/src/table/table.repository.ts b/packages/persistence/src/table/table.repository.ts index 31c3cd860..492685e8f 100644 --- a/packages/persistence/src/table/table.repository.ts +++ b/packages/persistence/src/table/table.repository.ts @@ -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)) diff --git a/packages/persistence/src/underlying/underlying-table-spec.visitor.ts b/packages/persistence/src/underlying/underlying-table-spec.visitor.ts index db8a51942..f2eca6499 100644 --- a/packages/persistence/src/underlying/underlying-table-spec.visitor.ts +++ b/packages/persistence/src/underlying/underlying-table-spec.visitor.ts @@ -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 diff --git a/packages/persistence/src/underlying/underlying-table.service.ts b/packages/persistence/src/underlying/underlying-table.service.ts index 6cc765cae..02498ea9a 100644 --- a/packages/persistence/src/underlying/underlying-table.service.ts +++ b/packages/persistence/src/underlying/underlying-table.service.ts @@ -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)