From 4766d21340398c1c330c371f7fbd38df4952c9de Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 9 Feb 2021 18:57:32 +0000 Subject: [PATCH] clean up index on table deletion --- .../DataTable/modals/CreateEditColumn.svelte | 14 +++----------- packages/server/src/api/controllers/table.js | 9 +++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index deefd3fe74..c42803a241 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -89,22 +89,14 @@ } function onChangePrimaryIndex(e) { - const enabled = e.target.checked - if (enabled) { - indexes[0] = field.name - } else { - indexes.shift() - indexes = indexes - } + indexes = e.target.checked ? [field.name] : [] } function onChangeSecondaryIndex(e) { - const enabled = e.target.checked - if (enabled) { + if (e.target.checked) { indexes[1] = field.name } else { - indexes.pop() - indexes = indexes + indexes = indexes.slice(0, 1) } } diff --git a/packages/server/src/api/controllers/table.js b/packages/server/src/api/controllers/table.js index 8abc6a0fff..1fa77b0b2b 100644 --- a/packages/server/src/api/controllers/table.js +++ b/packages/server/src/api/controllers/table.js @@ -212,6 +212,15 @@ exports.destroy = async function(ctx) { // don't remove the table itself until very end await db.remove(tableToDelete) + // remove table search index + const currentIndexes = await db.getIndexes() + const existingIndex = currentIndexes.indexes.find( + existing => existing.name === `search:${ctx.params.tableId}` + ) + if (existingIndex) { + await db.deleteIndex(existingIndex) + } + ctx.eventEmitter && ctx.eventEmitter.emitTable(`table:delete`, appId, tableToDelete) ctx.status = 200