Attempting to fix some potential app migration issues around versions.

This commit is contained in:
mike12345567 2024-06-10 22:38:16 +01:00
parent 26c2904f51
commit 4c873b9921
2 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { Duration, cache, context, db, env } from "@budibase/backend-core" import { Duration, cache, db, env } from "@budibase/backend-core"
import { Database, DocumentType, Document } from "@budibase/types" import { Database, DocumentType, Document } from "@budibase/types"
export interface AppMigrationDoc extends Document { export interface AppMigrationDoc extends Document {
@ -42,7 +42,10 @@ export async function getAppMigrationVersion(appId: string): Promise<string> {
version = "" version = ""
} }
// only cache if we have a valid version
if (version) {
await cache.store(cacheKey, version, EXPIRY_SECONDS) await cache.store(cacheKey, version, EXPIRY_SECONDS)
}
return version return version
} }
@ -54,8 +57,7 @@ export async function updateAppMigrationMetadata({
appId: string appId: string
version: string version: string
}): Promise<void> { }): Promise<void> {
const db = context.getAppDB() const appDb = db.getDB(appId)
let appMigrationDoc: AppMigrationDoc let appMigrationDoc: AppMigrationDoc
try { try {
@ -70,7 +72,7 @@ export async function updateAppMigrationMetadata({
version: "", version: "",
history: {}, history: {},
} }
await db.put(appMigrationDoc) await appDb.put(appMigrationDoc)
appMigrationDoc = await getFromDB(appId) appMigrationDoc = await getFromDB(appId)
} }
@ -82,7 +84,7 @@ export async function updateAppMigrationMetadata({
[version]: { runAt: new Date().toISOString() }, [version]: { runAt: new Date().toISOString() },
}, },
} }
await db.put(updatedMigrationDoc) await appDb.put(updatedMigrationDoc)
const cacheKey = getCacheKey(appId) const cacheKey = getCacheKey(appId)

View File

@ -16,7 +16,10 @@ export type AppMigration = {
export function getLatestEnabledMigrationId(migrations?: AppMigration[]) { export function getLatestEnabledMigrationId(migrations?: AppMigration[]) {
let latestMigrationId: string | undefined let latestMigrationId: string | undefined
for (let migration of migrations || MIGRATIONS) { if (!migrations) {
migrations = MIGRATIONS
}
for (let migration of migrations) {
// if a migration is disabled, all migrations after it are disabled // if a migration is disabled, all migrations after it are disabled
if (migration.disabled) { if (migration.disabled) {
break break