From e40c16621265e0858e8e72439ff5a47e16455532 Mon Sep 17 00:00:00 2001 From: Haoqian Li Date: Tue, 23 Jun 2026 23:59:35 +0800 Subject: [PATCH 1/2] test: include constraint definitions in upgrade snapshots --- scripts/test-upgrade.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/scripts/test-upgrade.sh b/scripts/test-upgrade.sh index 1778543..ac527c0 100755 --- a/scripts/test-upgrade.sh +++ b/scripts/test-upgrade.sh @@ -531,19 +531,17 @@ ORDER BY t.typname; -- Constraints SELECT 'constraint' AS obj_type, - tc.table_name, - tc.constraint_name, - tc.constraint_type, - string_agg(kcu.column_name, ', ' ORDER BY kcu.ordinal_position) AS columns, - '' AS extra1, + rel.relname AS table_name, + con.conname AS constraint_name, + con.contype::text AS constraint_type, + pg_get_constraintdef(con.oid) AS definition, + con.convalidated::text AS validated, '' AS extra2 -FROM information_schema.table_constraints tc -JOIN information_schema.key_column_usage kcu - ON tc.constraint_name = kcu.constraint_name - AND tc.table_schema = kcu.table_schema -WHERE tc.table_schema = 'df' -GROUP BY tc.table_name, tc.constraint_name, tc.constraint_type -ORDER BY tc.table_name, tc.constraint_name; +FROM pg_constraint con +JOIN pg_class rel ON rel.oid = con.conrelid +JOIN pg_namespace n ON n.oid = rel.relnamespace +WHERE n.nspname = 'df' +ORDER BY rel.relname, con.conname; -- RLS policies SELECT 'policy' AS obj_type, From 4bbf22552a9da47a8ff39bad82a1087e846d17c4 Mon Sep 17 00:00:00 2001 From: Pino de Candia <32303022+pinodeca@users.noreply.github.com> Date: Tue, 23 Jun 2026 22:57:58 +0000 Subject: [PATCH 2/2] Exclude NOT NULL constraints from schema snapshot NOT NULL column constraints are first-class pg_constraint rows on PG18+ but not on PG17 (they live in pg_attribute.attnotnull), which would make the constraint snapshot PG-version-dependent. Per-column nullability is already captured by the 'column' section via is_nullable, so filter out contype = 'n' to keep the snapshot deterministic across PG versions while preserving the CHECK body / convalidated comparison from issue #241. --- scripts/test-upgrade.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/test-upgrade.sh b/scripts/test-upgrade.sh index ac527c0..3e05e84 100755 --- a/scripts/test-upgrade.sh +++ b/scripts/test-upgrade.sh @@ -530,6 +530,16 @@ GROUP BY t.typname, t.typtype, t.typbasetype, t.typtypmod ORDER BY t.typname; -- Constraints +-- +-- Read from pg_constraint so CHECK bodies (pg_get_constraintdef) and the +-- validated/NOT VALID state (convalidated) are compared, not just key columns. +-- +-- Exclude NOT NULL constraints (contype = 'n'): on PG18+ these are first-class +-- pg_constraint rows, but on PG17 they are not (they live in +-- pg_attribute.attnotnull), so including them would make this snapshot +-- PG-version-dependent. Per-column nullability is already captured by the +-- 'column' section above via is_nullable, and the auto-generated NOT NULL +-- constraint names add noise without extra coverage. SELECT 'constraint' AS obj_type, rel.relname AS table_name, con.conname AS constraint_name, @@ -541,6 +551,7 @@ FROM pg_constraint con JOIN pg_class rel ON rel.oid = con.conrelid JOIN pg_namespace n ON n.oid = rel.relnamespace WHERE n.nspname = 'df' + AND con.contype <> 'n' ORDER BY rel.relname, con.conname; -- RLS policies