Updating app migration to use a slightly different mechanism to allow disabling the migration pipeline.
This commit is contained in:
parent
4f6076d2ba
commit
80ddadbe06
|
@ -10,8 +10,14 @@ export * from "./appMigrationMetadata"
|
||||||
export type AppMigration = {
|
export type AppMigration = {
|
||||||
id: string
|
id: string
|
||||||
func: () => Promise<void>
|
func: () => Promise<void>
|
||||||
|
// disabled so that by default all migrations listed are enabled
|
||||||
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// all migrations must be enabled for migrations to run
|
||||||
|
export const migrationsEnabled = (): boolean =>
|
||||||
|
MIGRATIONS.find(m => m.disabled) == null
|
||||||
|
|
||||||
export const getLatestMigrationId = () =>
|
export const getLatestMigrationId = () =>
|
||||||
MIGRATIONS.map(m => m.id)
|
MIGRATIONS.map(m => m.id)
|
||||||
.sort()
|
.sort()
|
||||||
|
|
|
@ -6,12 +6,10 @@ import { AppMigration } from "."
|
||||||
import m20240604153647_initial_sqs from "./migrations/20240604153647_initial_sqs"
|
import m20240604153647_initial_sqs from "./migrations/20240604153647_initial_sqs"
|
||||||
|
|
||||||
// Migrations will be executed sorted by ID
|
// Migrations will be executed sorted by ID
|
||||||
export const MIGRATIONS: AppMigration[] = []
|
export const MIGRATIONS: AppMigration[] = [
|
||||||
|
{
|
||||||
// only run the SQS migration if SQS is enabled
|
|
||||||
if (env.SQS_SEARCH_ENABLE) {
|
|
||||||
MIGRATIONS.push({
|
|
||||||
id: "20240604153647_initial_sqs",
|
id: "20240604153647_initial_sqs",
|
||||||
func: m20240604153647_initial_sqs,
|
func: m20240604153647_initial_sqs,
|
||||||
})
|
disabled: !env.SQS_SEARCH_ENABLE,
|
||||||
}
|
},
|
||||||
|
]
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { UserCtx } from "@budibase/types"
|
import { UserCtx } from "@budibase/types"
|
||||||
import { checkMissingMigrations } from "../appMigrations"
|
import { checkMissingMigrations, migrationsEnabled } from "../appMigrations"
|
||||||
import { env } from "@budibase/backend-core"
|
import { env } from "@budibase/backend-core"
|
||||||
|
|
||||||
export default async (ctx: UserCtx, next: any) => {
|
export default async (ctx: UserCtx, next: any) => {
|
||||||
const { appId } = ctx
|
const { appId } = ctx
|
||||||
|
|
||||||
if (env.SKIP_APP_MIGRATIONS) {
|
// migrations can be disabled via environment variable, or can be disabled
|
||||||
|
// due to some of the migrations not being ready to run - disables all migrations
|
||||||
|
if (env.SKIP_APP_MIGRATIONS || !migrationsEnabled()) {
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue