From bd8c52094b5c12462c59e312bee392e6435ffaef Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 5 Dec 2023 12:37:21 +0100 Subject: [PATCH] Initalise migration version on creation --- packages/server/src/api/controllers/application.ts | 6 ++++++ packages/server/src/appMigrations/index.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/application.ts b/packages/server/src/api/controllers/application.ts index b2b7a3e5cb..a6352be44b 100644 --- a/packages/server/src/api/controllers/application.ts +++ b/packages/server/src/api/controllers/application.ts @@ -52,6 +52,7 @@ import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts" import sdk from "../../sdk" import { builderSocket } from "../../websockets" import { sdk as sharedCoreSDK } from "@budibase/shared-core" +import * as appMigrations from "../../appMigrations" // utility function, need to do away with this async function getLayouts() { @@ -334,6 +335,11 @@ async function performAppCreate(ctx: UserCtx) { /* istanbul ignore next */ if (!env.isTest()) { await createApp(appId) + // Initialise app migration version + await appMigrations.updateAppMigrationMetadata({ + appId, + version: appMigrations.latestMigration, + }) } await cache.app.invalidateAppMetadata(appId, newApplication) diff --git a/packages/server/src/appMigrations/index.ts b/packages/server/src/appMigrations/index.ts index 1226333d96..3efe38e55a 100644 --- a/packages/server/src/appMigrations/index.ts +++ b/packages/server/src/appMigrations/index.ts @@ -2,14 +2,18 @@ import queue from "./queue" import { getAppMigrationVersion } from "./appMigrationMetadata" import { MIGRATIONS } from "./migrations" -const latestMigration = MIGRATIONS.map(m => m.migrationId) +export * from "./appMigrationMetadata" + +export const latestMigration = MIGRATIONS.map(m => m.migrationId) .sort() .reverse()[0] +const getTimestamp = (versionId: string) => versionId.split("_")[0] + export async function checkMissingMigrations(appId: string) { const currentVersion = await getAppMigrationVersion(appId) - if (currentVersion < latestMigration) { + if (getTimestamp(currentVersion) < getTimestamp(latestMigration)) { await queue.add( { appId,