Skip to content

fix: exclude partial unique indexes from DMMF unique fields#5792

Merged
jacek-prisma merged 1 commit intoprisma:mainfrom
jay-l-e-e:fix/exclude-partial-unique-from-dmmf
Mar 9, 2026
Merged

fix: exclude partial unique indexes from DMMF unique fields#5792
jacek-prisma merged 1 commit intoprisma:mainfrom
jay-l-e-e:fix/exclude-partial-unique-from-dmmf

Conversation

@jay-l-e-e
Copy link
Copy Markdown
Contributor

@jay-l-e-e jay-l-e-e commented Mar 7, 2026

Closes #5791

Summary

  • Exclude partial unique indexes (@@unique with where clause) from DMMF uniqueFields and uniqueIndexes
  • Set isUnique: false for single-field partial unique constraints
  • Add is_partial_unique() method to ScalarFieldWalker
  • Add regression test for partial unique index DMMF output

Context

Partial unique constraints don't guarantee uniqueness across all rows, so generating findUnique input types for them is incorrect. This fix ensures Prisma Client treats partial unique indexes as regular indexes rather than unique constraints.

Related: prisma/prisma#29282

Summary by CodeRabbit

  • New Features

    • Added support for detecting and properly handling partial unique constraints in the schema, enabling conditional uniqueness requirements (e.g., unique indexes on non-deleted records).
  • Tests

    • Added test fixtures validating partial unique index behavior in schema generation and representation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0d9c17dc-50c1-48f3-9265-64b03ea32265

📥 Commits

Reviewing files that changed from the base of the PR and between 94a226b and 2f825be.

📒 Files selected for processing (4)
  • psl/parser-database/src/walkers/scalar_field.rs
  • query-compiler/dmmf/src/ast_builders/datamodel_ast_builder.rs
  • query-compiler/dmmf/test_files/partial_unique_index.json
  • query-compiler/dmmf/test_files/partial_unique_index.prisma

Walkthrough

This PR adds detection and filtering logic for partial unique indexes in DMMF output. A new method identifies partial unique constraints on scalar fields, and the DMMF builder excludes partial indexes from uniqueness reporting to prevent incorrect findUnique generation.

Changes

Cohort / File(s) Summary
Scalar Field Walker
psl/parser-database/src/walkers/scalar_field.rs
Added is_partial_unique() method that checks if a field has a unique partial index by iterating model indexes for matching unique, partial, single-field constraints.
DMMF Builder
query-compiler/dmmf/src/ast_builders/datamodel_ast_builder.rs
Excludes partial indexes from uniqueness reporting by filtering out partial indexes in unique_fields/unique_indexes and tightening field-level uniqueness checks to reject partial unique fields.
Test Fixtures
query-compiler/dmmf/test_files/partial_unique_index.prisma, query-compiler/dmmf/test_files/partial_unique_index.json
Added schema test fixture defining User and Post models with partial unique indexes on email and (title, authorId) respectively, with deletedAt null conditions.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: excluding partial unique indexes from DMMF unique fields, which is the primary objective of the PR.
Linked Issues check ✅ Passed The PR fully addresses issue #5791 by excluding partial unique indexes from DMMF uniqueFields/uniqueIndexes and preventing findUnique generation for partial constraints.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: adding is_partial_unique() method, filtering partial indexes from DMMF output, and adding regression tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

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

@jay-l-e-e
Copy link
Copy Markdown
Contributor Author

Hi @jacek-prisma. Please review these changes! Thank you.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 9, 2026

Merging this PR will not alter performance

✅ 11 untouched benchmarks
⏩ 11 skipped benchmarks1


Comparing jay-l-e-e:fix/exclude-partial-unique-from-dmmf (2f825be) with main (94a226b)

Open in CodSpeed

Footnotes

  1. 11 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@jacek-prisma jacek-prisma merged commit 7b83011 into prisma:main Mar 9, 2026
94 of 99 checks passed
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.

Exclude partial unique indexes from DMMF unique fields/indexes

2 participants