diff --git a/admin-compliance/app/api/sdk/v1/master-controls/route.ts b/admin-compliance/app/api/sdk/v1/master-controls/route.ts index 6c443e29..214f821b 100644 --- a/admin-compliance/app/api/sdk/v1/master-controls/route.ts +++ b/admin-compliance/app/api/sdk/v1/master-controls/route.ts @@ -15,10 +15,13 @@ const pool = new Pool({ connectionString: dbUrl }) let metaCache: { at: number; data: unknown } | null = null const META_TTL_MS = 120_000 -// The use-case mapping tables (mc_use_case_mappings/mc_verification/mc_regulations) -// are seeded per-environment and may not exist yet on a fresh/unseeded DB. Guard -// every mapping query so the route degrades to empty filters instead of a 500. -// Cached with a short TTL so it picks up the tables once that DB gets seeded. +// The use-case mapping tables (mc_use_case_mappings, mc_verification, +// mc_regulations, mc_use_case_sync_state) are seeded together per-environment +// and may not exist yet on a fresh/unseeded DB. We probe mc_use_case_mappings as +// the existence sentinel and guard every mapping query so the route degrades to +// empty filters instead of a 500. Short TTL so it picks up the tables once seeded. +// NB: the sentinel assumes the siblings are seeded together — a half-seeded DB +// (mappings present but e.g. mc_regulations missing) would still 500 on those. let mappingTablesCache: { at: number; present: boolean } | null = null async function hasMappingTables(): Promise { if (mappingTablesCache && Date.now() - mappingTablesCache.at < 300_000) {