budibase/packages/server/src/appMigrations/index.ts

25 lines
574 B
TypeScript
Raw Normal View History

2023-11-29 13:28:52 +01:00
import queue from "./queue"
import { getAppMigrationVersion } from "./appMigrationMetadata"
2023-11-27 15:40:37 +01:00
import { MIGRATIONS } from "./migrations"
2023-11-29 13:28:52 +01:00
const latestMigration = MIGRATIONS.map(m => m.migrationId)
.sort()
.reverse()[0]
2023-11-27 15:40:37 +01:00
export async function checkMissingMigrations(appId: string) {
2023-11-29 13:28:52 +01:00
const currentVersion = await getAppMigrationVersion(appId)
2023-11-27 15:40:37 +01:00
if (currentVersion < latestMigration) {
await queue.add(
{
appId,
2023-11-27 16:23:57 +01:00
},
{
2023-11-29 11:03:33 +01:00
jobId: `${appId}_${latestMigration}`,
2023-11-27 16:23:57 +01:00
removeOnComplete: true,
removeOnFail: true,
2023-11-27 15:40:37 +01:00
}
)
}
}