fix(schema-engine): use allowlist in pg constraints query to handle PostgreSQL 18 NOT NULL contype#5819
Conversation
…ostgreSQL 18 NOT NULL contype
PostgreSQL 18 adds NOT NULL constraints as first-class pg_constraint rows
with contype = 'n'. The previous denylist `NOT IN ('p', 'u', 'f')` let
these rows through to get_constraints, where get_expect_char("constraint_type")
panics when the value arrives as Text (the driver-adapter value path).
Switching to an allowlist `IN ('c', 'x')` — the only two contypes the
describer actually handles (check and exclusion constraints) — prevents any
unknown or future contype from reaching the panic site. Column nullability
is already read from pg_attribute.attnotnull, so NOT-NULL-as-constraint rows
carry no information Prisma needs.
Fixes prisma/prisma#29635
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughThe PostgreSQL constraints introspection query in 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Change the PostgreSQL constraint introspection query from a denylist to an allowlist.
Before:
After:
Why
PostgreSQL 18 introduces NOT NULL constraints as first-class
pg_constraintrows withcontype = 'n'(PG 18 docs). The previous denylist allowed these rows through toget_constraints, whererow.get_expect_char("constraint_type")panics when the value arrives asText("n")rather than achar— which is the case for all driver-adapter paths, since values cross the JS boundary as strings.The practical impact: any PostgreSQL 18 database with at least one
NOT NULLcolumn (i.e. effectively all of them) breaksdb pushdiffing,db pull, andmigrate dev/deploywhen going through the WASM engine with a driver adapter (@prisma/adapter-pg, PGlite, etc.). The promise returned byschemaPushnever settles because the panic has no registered handler.The fix uses an allowlist restricted to
'c'(check) and'x'(exclusion) — the only twocontypevaluesget_constraintsactually handles. Column nullability is already read frompg_attribute.attnotnull, soNOT-NULL-as-constraintrows carry no information Prisma needs. This also future-proofs the query against any newcontypevalues PostgreSQL might introduce (PG 18 also added't'for trigger constraints upstream).Fixes prisma/prisma#29635