Adding a try catch to log if something in the app migration queue fails to process.
This commit is contained in:
parent
5e38ee03f1
commit
85ab9ed2ed
|
@ -1,4 +1,4 @@
|
||||||
import { context, locks } from "@budibase/backend-core"
|
import { context, locks, logging } from "@budibase/backend-core"
|
||||||
import { LockName, LockType } from "@budibase/types"
|
import { LockName, LockType } from "@budibase/types"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -20,37 +20,42 @@ export async function processMigrations(
|
||||||
resource: appId,
|
resource: appId,
|
||||||
},
|
},
|
||||||
async () => {
|
async () => {
|
||||||
await context.doInAppMigrationContext(appId, async () => {
|
try {
|
||||||
let currentVersion = await getAppMigrationVersion(appId)
|
await context.doInAppMigrationContext(appId, async () => {
|
||||||
|
let currentVersion = await getAppMigrationVersion(appId)
|
||||||
|
|
||||||
const pendingMigrations = migrations
|
const pendingMigrations = migrations
|
||||||
.filter(m => m.id > currentVersion)
|
.filter(m => m.id > currentVersion)
|
||||||
.sort((a, b) => a.id.localeCompare(b.id))
|
.sort((a, b) => a.id.localeCompare(b.id))
|
||||||
|
|
||||||
const migrationIds = migrations.map(m => m.id).sort()
|
const migrationIds = migrations.map(m => m.id).sort()
|
||||||
|
|
||||||
let index = 0
|
let index = 0
|
||||||
for (const { id, func } of pendingMigrations) {
|
for (const { id, func } of pendingMigrations) {
|
||||||
const expectedMigration =
|
const expectedMigration =
|
||||||
migrationIds[migrationIds.indexOf(currentVersion) + 1]
|
migrationIds[migrationIds.indexOf(currentVersion) + 1]
|
||||||
|
|
||||||
if (expectedMigration !== id) {
|
if (expectedMigration !== id) {
|
||||||
throw `Migration ${id} could not run, update for "${id}" is running but ${expectedMigration} is expected`
|
throw `Migration ${id} could not run, update for "${id}" is running but ${expectedMigration} is expected`
|
||||||
|
}
|
||||||
|
|
||||||
|
const counter = `(${++index}/${pendingMigrations.length})`
|
||||||
|
console.info(`Running migration ${id}... ${counter}`, {
|
||||||
|
migrationId: id,
|
||||||
|
appId,
|
||||||
|
})
|
||||||
|
await func()
|
||||||
|
await updateAppMigrationMetadata({
|
||||||
|
appId,
|
||||||
|
version: id,
|
||||||
|
})
|
||||||
|
currentVersion = id
|
||||||
}
|
}
|
||||||
|
})
|
||||||
const counter = `(${++index}/${pendingMigrations.length})`
|
} catch (err) {
|
||||||
console.info(`Running migration ${id}... ${counter}`, {
|
logging.logAlert("Failed to run app migration", err)
|
||||||
migrationId: id,
|
throw err
|
||||||
appId,
|
}
|
||||||
})
|
|
||||||
await func()
|
|
||||||
await updateAppMigrationMetadata({
|
|
||||||
appId,
|
|
||||||
version: id,
|
|
||||||
})
|
|
||||||
currentVersion = id
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue