-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(schema): Provide a truncated name for unique constraints with polymorphic fk #1999
Conversation
📝 WalkthroughWalkthroughThis pull request updates the logic in the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant Generator as PrismaSchemaGenerator
participant Model as Model
Caller->>Generator: Call replicateForeignKeyModelLevelUnique(model, dataModel, origForeignKey, addedFkField)
Generator->>Generator: Check if argument is a ReferenceExpr
alt Argument is not a ReferenceExpr
Generator-->>Caller: Throw PluginError
else Argument is ReferenceExpr
Generator->>Generator: Replace original foreign key with new field name
Generator->>Generator: Collect field names for constraint naming
Generator->>Model: Invoke model.addAttribute(uniqueConstraint)
Generator-->>Caller: Return updated model
end
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/schema/src/plugins/prisma/schema-generator.ts
(2 hunks)tests/regression/tests/issue-1992.test.ts
(1 hunks)
🔇 Additional comments (3)
tests/regression/tests/issue-1992.test.ts (1)
52-53
: LGTM! The unique constraints are well-defined.The test correctly verifies the unique constraints on the
MyAppUserFolder
model:
@@unique([companyId, userId, name])
: Ensures unique folder names per user within a company.@@unique([companyId, userId, path])
: Ensures unique paths per user within a company.packages/schema/src/plugins/prisma/schema-generator.ts (2)
533-536
: LGTM! Improved error handling with explicit type check.The code now explicitly checks for unexpected field references in the
@@unique
attribute, which helps catch potential issues early.
558-562
: LGTM! Improved unique constraint name generation.The code now:
- Collects field names to generate a descriptive constraint name.
- Uses the
truncate
method to ensure the name fits within database limits.- Adds the constraint name to the unique attribute using the
map
argument.
9252250
to
f4fdb1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! Thank you!
fixes #1992