fix: handle PostgreSQL identifier quoting in partial index predicate comparison#5788
Conversation
…n partial index predicate comparison
|
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)
WalkthroughAdds semantic identifier comparison to the Postgres schema differ to treat quoted and unquoted identifiers as equivalent in predicate ASTs, and adds a Postgres test ensuring a partial index with an object-literal where clause is idempotent across repeated pushes. Changes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
|
Hi @jacek-prisma, Please review these changes! Thank you. |
Merging this PR will not alter performance
Comparing Footnotes
|
Description
Closes #5787
Problem
After #5780, partial indexes with object literal
whereclauses are still recreated on every migration when predicates contain multiple conditions. PostgreSQL'spg_get_expr()returns unquoted identifiers for lowercase column names (postcode), while Prisma generates quoted identifiers ("postcode"). The AST comparison treats these as different, causing needless drop+recreate cycles.Solution
Extend
exprs_semantically_eqto treat quoted and unquoted identifiers as equivalent when the unquoted form is a valid PostgreSQL identifier. UsessqlparserwithPostgreSqlDialectto verify that the identifier value can be safely used without quotes (i.e., it's not a reserved keyword and follows identifier rules).Changes
schema_differ.rs— Added identifier quoting comparison inexprs_semantically_eq; checks if"foo"andfoorefer to the same column by re-parsing withsqlparserpartial.rs— Regression test for object literal predicates withnullandnot: nullconditionsSummary by CodeRabbit