Addressing PR comments.
This commit is contained in:
parent
244fbe42b1
commit
70aa43680d
|
@ -193,7 +193,6 @@ const environment = {
|
||||||
},
|
},
|
||||||
ROLLING_LOG_MAX_SIZE: process.env.ROLLING_LOG_MAX_SIZE || "10M",
|
ROLLING_LOG_MAX_SIZE: process.env.ROLLING_LOG_MAX_SIZE || "10M",
|
||||||
DISABLE_SCIM_CALLS: process.env.DISABLE_SCIM_CALLS,
|
DISABLE_SCIM_CALLS: process.env.DISABLE_SCIM_CALLS,
|
||||||
SKIP_APP_MIGRATIONS: process.env.SKIP_APP_MIGRATIONS || false,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean up any environment variable edge cases
|
// clean up any environment variable edge cases
|
||||||
|
|
|
@ -27,7 +27,7 @@ export async function getMigrationStatus(ctx: Ctx) {
|
||||||
|
|
||||||
const latestAppliedMigration = await getAppMigrationVersion(appId)
|
const latestAppliedMigration = await getAppMigrationVersion(appId)
|
||||||
|
|
||||||
const migrated = latestAppliedMigration === getLatestEnabledMigrationId()
|
const migrated = latestAppliedMigration >= getLatestEnabledMigrationId()
|
||||||
|
|
||||||
ctx.body = { migrated }
|
ctx.body = { migrated }
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
|
|
|
@ -14,9 +14,9 @@ export type AppMigration = {
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLatestEnabledMigrationId() {
|
export function getLatestEnabledMigrationId(migrations?: AppMigration[]) {
|
||||||
const enabledMigrations: AppMigration[] = []
|
const enabledMigrations: AppMigration[] = []
|
||||||
for (let migration of MIGRATIONS) {
|
for (let migration of migrations || MIGRATIONS) {
|
||||||
// if a migration is disabled, all migrations after it are disabled
|
// if a migration is disabled, all migrations after it are disabled
|
||||||
if (migration.disabled) {
|
if (migration.disabled) {
|
||||||
break
|
break
|
||||||
|
|
|
@ -43,15 +43,7 @@ const migration = async () => {
|
||||||
const tables = await sdk.tables.getAllInternalTables()
|
const tables = await sdk.tables.getAllInternalTables()
|
||||||
// do these one by one - running in parallel could cause problems
|
// do these one by one - running in parallel could cause problems
|
||||||
for (let table of tables) {
|
for (let table of tables) {
|
||||||
try {
|
|
||||||
await db.sql(`select * from ${table._id} limit 1`)
|
await db.sql(`select * from ${table._id} limit 1`)
|
||||||
} catch (err) {
|
|
||||||
if (typeof err === "object") {
|
|
||||||
const dbErr = err as DBError
|
|
||||||
throw new Error(`Failed to run initial SQS search - ${dbErr.message}`)
|
|
||||||
}
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Header } from "@budibase/backend-core"
|
import { Header } from "@budibase/backend-core"
|
||||||
import * as setup from "../../api/routes/tests/utilities"
|
import * as setup from "../../api/routes/tests/utilities"
|
||||||
import * as migrations from "../migrations"
|
import * as migrations from "../migrations"
|
||||||
import { getLatestEnabledMigrationId } from "../index"
|
import { AppMigration, getLatestEnabledMigrationId } from "../index"
|
||||||
import { getAppMigrationVersion } from "../appMigrationMetadata"
|
import { getAppMigrationVersion } from "../appMigrationMetadata"
|
||||||
|
|
||||||
jest.mock<typeof migrations>("../migrations", () => ({
|
jest.mock<typeof migrations>("../migrations", () => ({
|
||||||
|
@ -54,25 +54,28 @@ describe("migrations", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should disable migrations if any migration is disabled", () => {
|
it("should disable all migrations after one that is disabled", () => {
|
||||||
// remove all migrations
|
const MIGRATION_ID1 = "20231211105810_new-test",
|
||||||
migrations.MIGRATIONS.splice(0, migrations.MIGRATIONS.length)
|
MIGRATION_ID2 = "20231211105812_new-test",
|
||||||
migrations.MIGRATIONS.push({
|
MIGRATION_ID3 = "20231211105814_new-test"
|
||||||
id: "20231211105810_new-test",
|
// create some migrations to test with
|
||||||
|
const migrations: AppMigration[] = [
|
||||||
|
{
|
||||||
|
id: MIGRATION_ID1,
|
||||||
func: async () => {},
|
func: async () => {},
|
||||||
})
|
},
|
||||||
migrations.MIGRATIONS.push({
|
{
|
||||||
id: "20231211105812_new-test",
|
id: MIGRATION_ID2,
|
||||||
func: async () => {},
|
func: async () => {},
|
||||||
})
|
},
|
||||||
migrations.MIGRATIONS.push({
|
{
|
||||||
id: "20231211105814_new-test",
|
id: MIGRATION_ID3,
|
||||||
func: async () => {},
|
func: async () => {},
|
||||||
})
|
},
|
||||||
|
]
|
||||||
|
|
||||||
expect(getLatestEnabledMigrationId()).toBe("20231211105814_new-test")
|
expect(getLatestEnabledMigrationId(migrations)).toBe(MIGRATION_ID3)
|
||||||
|
migrations[1].disabled = true
|
||||||
migrations.MIGRATIONS[1].disabled = true
|
expect(getLatestEnabledMigrationId(migrations)).toBe(MIGRATION_ID1)
|
||||||
expect(getLatestEnabledMigrationId()).toBe("20231211105810_new-test")
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -5,8 +5,8 @@ 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
|
||||||
|
|
||||||
// migrations can be disabled via environment variable, or can be disabled
|
// migrations can be disabled via environment variable if you
|
||||||
// due to some of the migrations not being ready to run - disables all migrations
|
// need to completely disable migrations, e.g. for testing
|
||||||
if (env.SKIP_APP_MIGRATIONS) {
|
if (env.SKIP_APP_MIGRATIONS) {
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,12 @@ async function buildBaseDefinition(): Promise<PreSaveSQLiteDefinition> {
|
||||||
export async function syncDefinition(): Promise<void> {
|
export async function syncDefinition(): Promise<void> {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
let existing: SQLiteDefinition | undefined
|
let existing: SQLiteDefinition | undefined
|
||||||
if (await db.exists(SQLITE_DESIGN_DOC_ID)) {
|
try {
|
||||||
existing = await db.get<SQLiteDefinition>(SQLITE_DESIGN_DOC_ID)
|
existing = await db.get<SQLiteDefinition>(SQLITE_DESIGN_DOC_ID)
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.status !== 404) {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const definition = await buildBaseDefinition()
|
const definition = await buildBaseDefinition()
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
|
Loading…
Reference in New Issue