From ac53a97176bc43cbd63e05a8a7efc3d755247abd Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 6 Jun 2024 14:55:07 +0100 Subject: [PATCH 1/2] WIP --- packages/backend-core/src/db/couch/DatabaseImpl.ts | 2 ++ packages/server/src/api/routes/tests/application.spec.ts | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/backend-core/src/db/couch/DatabaseImpl.ts b/packages/backend-core/src/db/couch/DatabaseImpl.ts index 8194d1aabf..b3b51bf72e 100644 --- a/packages/backend-core/src/db/couch/DatabaseImpl.ts +++ b/packages/backend-core/src/db/couch/DatabaseImpl.ts @@ -360,6 +360,8 @@ export class DatabaseImpl implements Database { SQLITE_DESIGN_DOC_ID ) await this.remove(SQLITE_DESIGN_DOC_ID, definition._rev) + } catch (err: any) { + // design document doesn't exist, don't worry } finally { await this.sqlDiskCleanup() } diff --git a/packages/server/src/api/routes/tests/application.spec.ts b/packages/server/src/api/routes/tests/application.spec.ts index 7f89a5cac2..b571e6e1f7 100644 --- a/packages/server/src/api/routes/tests/application.spec.ts +++ b/packages/server/src/api/routes/tests/application.spec.ts @@ -331,9 +331,15 @@ describe("/applications", () => { it("should delete published app and dev app with prod app ID", async () => { await config.api.application.delete(app.appId.replace("_dev", "")) - expect(events.app.deleted).toHaveBeenCalledTimes(1) + expect(events.app.deleted).toHaveBeenCalledTmes(1) expect(events.app.unpublished).toHaveBeenCalledTimes(1) }) + + it.only("should be able to delete an app after SQS_SEARCH_ENABLE has been set but app hasn't been migrated", async () => { + await config.withCoreEnv({ SQS_SEARCH_ENABLE: "true" }, async () => { + await config.api.application.delete(app.appId) + }) + }) }) describe("POST /api/applications/:appId/duplicate", () => { From 2c86ea14fd5989a0791a5c6866d40619f0071a7b Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 6 Jun 2024 15:07:06 +0100 Subject: [PATCH 2/2] Changing how disk cleanup is performed. --- .../backend-core/src/db/couch/DatabaseImpl.ts | 21 +++++++------------ .../src/api/routes/tests/application.spec.ts | 4 ++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/backend-core/src/db/couch/DatabaseImpl.ts b/packages/backend-core/src/db/couch/DatabaseImpl.ts index b3b51bf72e..2b589ed09a 100644 --- a/packages/backend-core/src/db/couch/DatabaseImpl.ts +++ b/packages/backend-core/src/db/couch/DatabaseImpl.ts @@ -352,20 +352,15 @@ export class DatabaseImpl implements Database { } async destroy() { + if (env.SQS_SEARCH_ENABLE && (await this.exists(SQLITE_DESIGN_DOC_ID))) { + // delete the design document, then run the cleanup operation + const definition = await this.get(SQLITE_DESIGN_DOC_ID) + // remove all tables - save the definition then trigger a cleanup + definition.sql.tables = {} + await this.put(definition) + await this.sqlDiskCleanup() + } try { - if (env.SQS_SEARCH_ENABLE) { - // delete the design document, then run the cleanup operation - try { - const definition = await this.get( - SQLITE_DESIGN_DOC_ID - ) - await this.remove(SQLITE_DESIGN_DOC_ID, definition._rev) - } catch (err: any) { - // design document doesn't exist, don't worry - } finally { - await this.sqlDiskCleanup() - } - } return await this.nano().db.destroy(this.name) } catch (err: any) { // didn't exist, don't worry diff --git a/packages/server/src/api/routes/tests/application.spec.ts b/packages/server/src/api/routes/tests/application.spec.ts index b571e6e1f7..13b7451a7e 100644 --- a/packages/server/src/api/routes/tests/application.spec.ts +++ b/packages/server/src/api/routes/tests/application.spec.ts @@ -331,11 +331,11 @@ describe("/applications", () => { it("should delete published app and dev app with prod app ID", async () => { await config.api.application.delete(app.appId.replace("_dev", "")) - expect(events.app.deleted).toHaveBeenCalledTmes(1) + expect(events.app.deleted).toHaveBeenCalledTimes(1) expect(events.app.unpublished).toHaveBeenCalledTimes(1) }) - it.only("should be able to delete an app after SQS_SEARCH_ENABLE has been set but app hasn't been migrated", async () => { + it("should be able to delete an app after SQS_SEARCH_ENABLE has been set but app hasn't been migrated", async () => { await config.withCoreEnv({ SQS_SEARCH_ENABLE: "true" }, async () => { await config.api.application.delete(app.appId) })