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