1
0
Fork 0
mirror of synced 2024-09-09 22:16:26 +12:00

Addressing PR comments.

This commit is contained in:
mike12345567 2024-06-06 16:49:03 +01:00
parent 244fbe42b1
commit 70aa43680d
7 changed files with 34 additions and 36 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}
} }
} }
} }

View file

@ -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
func: async () => {}, const migrations: AppMigration[] = [
}) {
migrations.MIGRATIONS.push({ id: MIGRATION_ID1,
id: "20231211105812_new-test", func: async () => {},
func: async () => {}, },
}) {
migrations.MIGRATIONS.push({ id: MIGRATION_ID2,
id: "20231211105814_new-test", func: async () => {},
func: async () => {}, },
}) {
id: MIGRATION_ID3,
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")
}) })
}) })

View file

@ -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()
} }

View file

@ -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) {