File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,14 +142,13 @@ export async function createExample(sql: postgres.Sql, table: string) {
142142 tx : postgres . TransactionSql ,
143143 allowTargetIndexes : boolean ,
144144 ) {
145- // PostgreSQL 18 records NOT NULL constraints in pg_constraint, including the
146- // primary key's implicit one. Permit only that first-column obligation;
147- // pg_attribute also catches customer NOT NULL declarations on PostgreSQL 17.
148- // Source NOT NULL breaks target-only writes; target NOT NULL must survive rollback.
149145 const dependencies = await tx `SELECT
150146 EXISTS (SELECT 1 FROM pg_trigger WHERE tgrelid = ${ table } ::regclass AND NOT tgisinternal)
151147 OR EXISTS (SELECT 1 FROM pg_constraint WHERE (conrelid = ${ table } ::regclass OR confrelid = ${ table } ::regclass)
152- AND NOT (conrelid = ${ table } ::regclass AND contype IN ('p', 'n') AND 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.
153152 OR EXISTS (SELECT 1 FROM pg_attribute WHERE attrelid = ${ table } ::regclass
154153 AND attnum > 1 AND NOT attisdropped AND attnotnull)
155154 OR EXISTS (SELECT 1 FROM pg_index ix JOIN pg_class idx ON idx.oid = ix.indexrelid
You can’t perform that action at this time.
0 commit comments