Skip to content

Commit c549782

Browse files
committed
fix(e2e): accept the primary key's NOT NULL on PostgreSQL 18
PostgreSQL 18 lists the NOT NULL on a primary key column in pg_constraint (contype 'n'), so the upgrade example's preflight refused the table its own seed created. Exempt both the primary key and its NOT NULL on pk, and read NOT NULL from pg_attribute for every other column, so PostgreSQL 17 and 18 give the same answer.
1 parent 12083f5 commit c549782

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎e2e/migration-guide/postgres.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ export async function createExample(sql: postgres.Sql, table: string) {
145145
const dependencies = await tx`SELECT
146146
EXISTS (SELECT 1 FROM pg_trigger WHERE tgrelid = ${table}::regclass AND NOT tgisinternal)
147147
OR EXISTS (SELECT 1 FROM pg_constraint WHERE (conrelid = ${table}::regclass OR confrelid = ${table}::regclass)
148-
AND (contype <> 'p' OR conkey <> ARRAY[1]::smallint[]))
148+
-- PostgreSQL 18 also lists the primary key column's NOT NULL here.
149+
AND NOT (contype IN ('p', 'n') AND conrelid = ${table}::regclass AND conkey = ARRAY[1]::smallint[]))
150+
-- PostgreSQL 17 and earlier keep NOT NULL out of pg_constraint, so read
151+
-- it from the column on every version.
152+
OR EXISTS (SELECT 1 FROM pg_attribute WHERE attrelid = ${table}::regclass
153+
AND attnum > 1 AND NOT attisdropped AND attnotnull)
149154
OR EXISTS (SELECT 1 FROM pg_index ix JOIN pg_class idx ON idx.oid = ix.indexrelid
150155
WHERE indrelid = ${table}::regclass AND NOT indisprimary AND NOT (
151156
${allowTargetIndexes} AND NOT indisunique AND indpred IS NULL AND indnatts = 1

0 commit comments

Comments
 (0)