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