Reused existing relation name to produce opposite relation while expanding polymorphic relations#1572
Conversation
…nding polymorphic relations
WalkthroughWalkthroughThe recent changes introduce a new Changes
Sequence Diagram(s)sequenceDiagram
participant Developer
participant PrismaSchemaGenerator
participant Codebase
Developer->>PrismaSchemaGenerator: Add new `nameArg` to extract 'name'
PrismaSchemaGenerator->>Codebase: Use `nameArg` to set relation names
Note right of Codebase: Relations have correct names
Developer->>PrismaSchemaGenerator: Run tests in `issue-1575.test.ts`
PrismaSchemaGenerator->>Codebase: Validate schema models and relations
Codebase-->>Developer: Test results (success/failure)
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/schema/src/plugins/prisma/schema-generator.ts (2 hunks)
Additional comments not posted (2)
packages/schema/src/plugins/prisma/schema-generator.ts (2)
413-413: IntroducenameArgto extract the 'name' attribute fromrelAttr.The introduction of
nameArgis to extract the 'name' attribute from a relation attribute (relAttr). This is a good practice to ensure that existing relation names are reused if available. This change is consistent with the PR objective to maintain consistency and avoid breaking model generation.
443-443: EnsurenameArgis used correctly in the relation attribute.The usage of
nameArg?.value || auxRelationField.nameensures that the existing relation name is used if available, otherwise, it falls back to the auxiliary relation field name. This aligns with the goal of reusing existing relation names and maintaining consistency.
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 5032426 | Triggered | Generic Password | d0eaf25 | tests/integration/tests/enhancements/with-policy/field-validation.test.ts | View secret |
| 5032426 | Triggered | Generic Password | d0eaf25 | tests/integration/tests/enhancements/with-policy/field-validation.test.ts | View secret |
| 5032426 | Triggered | Generic Password | 0dfc81f | tests/integration/tests/enhancements/with-policy/field-validation.test.ts | View secret |
| 5032426 | Triggered | Generic Password | 0dfc81f | tests/integration/tests/enhancements/with-policy/field-validation.test.ts | View secret |
| 8777145 | Triggered | Username Password | b9c7572 | packages/testtools/src/db.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
…n-name-in-polimorphic
|
Hi @irvinzz , thanks for making this fix! I've added a test case and merged with parent branch "dev". Will merge this PR once CI passes. |
|
Fixes #1575 |
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/schema/src/plugins/prisma/schema-generator.ts (2 hunks)
- tests/regression/tests/issue-1575.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/schema/src/plugins/prisma/schema-generator.ts
Additional comments not posted (2)
tests/regression/tests/issue-1575.test.ts (2)
1-1: Import statement looks good.The
loadSchemafunction is correctly imported from@zenstackhq/testtools.
2-29: Test case structure and content look good.The
describeblock anditblock are correctly structured, and the schema definitions align with the PR description for issue 1575.
Issue
expandPolymorphicRelationsfunction always use generated relation name even it already exists.Description
Named foreign key relation breaks model generation when it points to delegate type
Reproduce
Opposite relations
delegate_aux_UserAssets_videoStream_Movie<=>userVideoanddelegate_aux_UserAssets_subtitlesAsset_Movie<=>userSubtitleshas different relation names.zmodel source
Logical prisma schema