Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion scripts/supabase-target/invariants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,15 @@ export async function validateIntegrityConstraints(client: PgClient): Promise<st
CANONICAL_PROVIDER_KEY_CONSTRAINT,
]) {
const row = result.rows.find((candidate) => candidate["conname"] === contract.name);
if (row && normalizedSqlDefinition(row["definition"]) !== contract.definition) {
// pg_get_constraintdef's AND-chain grouping changed between Postgres
// minors (17.4 prints left-associated parentheses, 17.6 flattens), so the
// comparison ignores parentheses. Operator, literal, and regex changes
// still surface, which is what this drift check exists to catch.
if (
row &&
parenInsensitiveSqlDefinition(row["definition"]) !==
parenInsensitiveSqlDefinition(contract.definition)
) {
issues.push(`Security check public.${contract.tableName}.${contract.name} has drifted.`);
}
}
Expand Down Expand Up @@ -261,3 +269,7 @@ function stringField(row: Record<string, unknown>, key: string): string | undefi
function normalizedSqlDefinition(value: unknown): string {
return typeof value === "string" ? value.replaceAll(/\s+/g, " ").trim() : "";
}

function parenInsensitiveSqlDefinition(value: unknown): string {
return normalizedSqlDefinition(value).replaceAll(/[()]/g, "").replaceAll(/\s+/g, " ").trim();
}