From 25c16ae22923a4372c7a243ffd53867b500a83c8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 29 Nov 2023 11:16:10 +0100 Subject: [PATCH] Add migration integrity tests --- .../appMigrations/tests/migrations.spec.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 packages/server/src/appMigrations/tests/migrations.spec.ts diff --git a/packages/server/src/appMigrations/tests/migrations.spec.ts b/packages/server/src/appMigrations/tests/migrations.spec.ts new file mode 100644 index 0000000000..c2fddc2766 --- /dev/null +++ b/packages/server/src/appMigrations/tests/migrations.spec.ts @@ -0,0 +1,26 @@ +import { context } from "@budibase/backend-core" +import * as setup from "../../api/routes/tests/utilities" +import { MIGRATIONS } from "../migrations" +import { runMigration } from "../queue" + +describe("migration", () => { + it("each migration can rerun safely", async () => { + const config = setup.getConfig() + await config.init() + + const migrations = Object.keys(MIGRATIONS) + + await config.doInContext(config.getAppId(), async () => { + const db = context.getAppDB() + for (const migration of migrations) { + await runMigration(migration) + const docs = await db.allDocs({ include_docs: true }) + + await runMigration(migration) + const latestDocs = await db.allDocs({ include_docs: true }) + + expect(docs).toEqual(latestDocs) + } + }) + }) +})