prisma-engines
6bddf567 - fix: use AST comparison for partial index predicates on PostgreSQL and MSSQL (#5780)

Commit
65 days ago
fix: use AST comparison for partial index predicates on PostgreSQL and MSSQL (#5780) Closes https://github.com/prisma/prisma/issues/29175 and https://github.com/prisma/prisma-engines/issues/5779 ## Problem PostgreSQL and MSSQL normalize index predicate expressions when storing them. PG rewrites operators (`!=` → `<>`), adds implicit casts on literals (`(0)::numeric`), and wraps in parens. MSSQL collapses whitespace around operators and wraps in parens (`[status] = 'active'` → `([status]='active')`). The differ compared predicates with plain string equality, so every `schema_push` / `migrate dev` saw a mismatch and generated a needless drop+recreate. ## Solution Parse both predicates with `sqlparser` (using the appropriate dialect) and compare the ASTs after stripping DB-specific normalizations (outer parens, type casts on literal values for PG). `sqlparser` naturally handles whitespace and already normalizes `!=` / `<>` to the same `BinaryOperator::NotEq`. ## Changes - **PG** `schema_differ.rs` — `predicates_match` falls through to `pg_predicates_semantically_equal` when strings differ; strips `Nested` + literal `Cast` - **MSSQL** `schema_differ.rs` — `predicates_match` override added with `mssql_predicates_semantically_equal`; strips `Nested`. Also removed redundant predicate check from `indexes_match` (already handled by caller in `table.rs`) - **`partial.rs`** — four regression tests: two PG (enum cast, numeric literal cast) and two MSSQL (whitespace normalization, comparison normalization)
Author
Parents
Loading