Skip to content

fix(schema-engine): match implicit text casts - #5856

Open
danez wants to merge 1 commit into
prisma:mainfrom
danez:patch-1
Open

danez wants to merge 1 commit into
prisma:mainfrom
danez:patch-1

Conversation

@danez

@danez danez commented Aug 7, 2026 •

Copy link
Copy Markdown

Summary

Fix PostgreSQL partial-index migration drift for @db.VarChar fields.

This directly fixes prisma/orm#29386.

PostgreSQL normalizes partial-index predicates by adding ::text casts
to VARCHAR column identifiers and string literals. The schema differ
previously handled the literal cast but not the identifier cast, so
migrate dev repeatedly generated a no-op drop/create-index migration.

The predicate comparator now treats an identifier and its implicit
::text form as equivalent. Other casts remain significant.

Fixes prisma/orm#29386

Test

  • Added a PostgreSQL regression test that creates a migration for a
    partial unique index on VARCHAR fields, then verifies an unchanged
    schema does not create a second migration.

  • Ran:

    cargo test -p sql-migration-tests --test migration_tests -- --nocapture

AI assistance

AI assistance was used to investigate the PostgreSQL predicate normalization
and draft the regression test. The implementation and test result were
reviewed and verified locally.

PostgreSQL adds ::text to varchar partial-index predicates.
Treat the normalized identifier form as equal to Prisma's generated form.

Fixes prisma/orm#29386
@CLAassistant

CLAassistant commented Aug 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes

    • Improved PostgreSQL schema comparison for expressions using redundant ::text casts, reducing unnecessary migration changes.
  • Tests

    • Added coverage for PostgreSQL partial unique indexes with string predicates.
    • Verified that unchanged schemas do not generate additional migrations.

Walkthrough

The PostgreSQL schema differ now treats identifier and compound-identifier expressions with equivalent ::text casts as semantically equal. The comparison checks both casted and uncasted forms recursively. A PostgreSQL migration test covers partial unique indexes with string predicates and verifies that unchanged schemas do not generate an additional migration.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing semantic matching for implicit PostgreSQL text casts.
Description check ✅ Passed The description directly explains the PostgreSQL partial-index migration drift, the comparator fix, the regression test, and verification performed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prisma migrate infinite generation loop with varchar partial unique index

2 participants