Add tests
This commit is contained in:
parent
2a92263df5
commit
144fbdf946
|
@ -340,7 +340,7 @@ async function performAppCreate(ctx: UserCtx) {
|
|||
// Initialise the app migration version as the latest one
|
||||
await appMigrations.updateAppMigrationMetadata({
|
||||
appId,
|
||||
version: appMigrations.latestMigration,
|
||||
version: appMigrations.getLatestMigrationId(),
|
||||
})
|
||||
|
||||
await cache.app.invalidateAppMetadata(appId, newApplication)
|
||||
|
|
|
@ -12,9 +12,10 @@ export type AppMigration = {
|
|||
func: () => Promise<void>
|
||||
}
|
||||
|
||||
export const latestMigration = MIGRATIONS.map(m => m.id)
|
||||
.sort()
|
||||
.reverse()[0]
|
||||
export const getLatestMigrationId = () =>
|
||||
MIGRATIONS.map(m => m.id)
|
||||
.sort()
|
||||
.reverse()[0]
|
||||
|
||||
const getTimestamp = (versionId: string) => versionId?.split("_")[0]
|
||||
|
||||
|
@ -24,6 +25,7 @@ export async function checkMissingMigrations(
|
|||
appId: string
|
||||
) {
|
||||
const currentVersion = await getAppMigrationVersion(appId)
|
||||
const latestMigration = getLatestMigrationId()
|
||||
|
||||
if (getTimestamp(currentVersion) < getTimestamp(latestMigration)) {
|
||||
await queue.add(
|
||||
|
|
|
@ -4,12 +4,14 @@ import { getAppMigrationVersion } from "../appMigrationMetadata"
|
|||
import { context } from "@budibase/backend-core"
|
||||
import { AppMigration } from ".."
|
||||
|
||||
const futureTimestamp = `20500101174029`
|
||||
|
||||
describe("migrationsProcessor", () => {
|
||||
it("running migrations will update the latest applied migration", async () => {
|
||||
const testMigrations: AppMigration[] = [
|
||||
{ id: "123", func: async () => {} },
|
||||
{ id: "124", func: async () => {} },
|
||||
{ id: "125", func: async () => {} },
|
||||
{ id: `${futureTimestamp}_123`, func: async () => {} },
|
||||
{ id: `${futureTimestamp}_124`, func: async () => {} },
|
||||
{ id: `${futureTimestamp}_125`, func: async () => {} },
|
||||
]
|
||||
|
||||
const config = setup.getConfig()
|
||||
|
@ -23,13 +25,13 @@ describe("migrationsProcessor", () => {
|
|||
|
||||
expect(
|
||||
await config.doInContext(appId, () => getAppMigrationVersion(appId))
|
||||
).toBe("125")
|
||||
).toBe(`${futureTimestamp}_125`)
|
||||
})
|
||||
|
||||
it("no context can be initialised within a migration", async () => {
|
||||
const testMigrations: AppMigration[] = [
|
||||
{
|
||||
id: "123",
|
||||
id: `${futureTimestamp}_123`,
|
||||
func: async () => {
|
||||
await context.doInAppMigrationContext("any", () => {})
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue