Files
Jyotisha/frontend/src/lib/health-database-contract.ts
T
Jesse_Chen 60cbe8a75e
Independent Staging Quality Gate / validate (push) Successful in 19m18s
Independent Staging Quality Gate / publish (push) Successful in 33m22s
fix(web): read migration filenames through a definer instead of app_runtime
Staging web never became healthy because /api/health selected migration.schema_migrations as app_runtime, which is forbidden, so Docker rolled the image back.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-26 20:21:49 +08:00

33 lines
1.1 KiB
TypeScript

/**
* Health contract for rectification schema. gitCommit proves the web image;
* latestMigration proves the business database actually applied the SQL.
*/
export const RECTIFICATION_CONTRACT_VERSION = "v4";
export const REQUIRED_RECTIFICATION_MIGRATIONS = [
"20260826010000_rectification_inference_round_audit.sql",
"20260826020000_rectification_choice_focus_identity.sql",
"20260826030000_rectification_migration_ledger_health.sql",
] as const;
export type DatabaseHealth = Readonly<{
latestMigration: string | null;
rectificationContractVersion: typeof RECTIFICATION_CONTRACT_VERSION;
requiredMigrationsPresent: boolean;
missingMigrations: readonly string[];
}>;
export function databaseHealthFromFilenames(
filenames: readonly string[],
): DatabaseHealth {
const present = new Set(filenames);
const missing = REQUIRED_RECTIFICATION_MIGRATIONS.filter((name) => !present.has(name));
const latest = [...filenames].sort().at(-1) ?? null;
return {
latestMigration: latest,
rectificationContractVersion: RECTIFICATION_CONTRACT_VERSION,
requiredMigrationsPresent: missing.length === 0,
missingMigrations: missing,
};
}