-
-
Notifications
You must be signed in to change notification settings - Fork 91
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: foreign key constraint ambiguity in generated delegate prisma schema #1060
Conversation
WalkthroughWalkthroughThis update introduces a new feature to address foreign key constraint ambiguity in database schemas with polymorphic relationships. By adding a Changes
Related issues
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- packages/schema/src/plugins/prisma/schema-generator.ts (1 hunks)
- tests/integration/tests/enhancements/with-delegate/regressions.test.ts (1 hunks)
Additional comments: 2
tests/integration/tests/enhancements/with-delegate/regressions.test.ts (1)
- 1-53: The test case for FK Constraint Ambiguity is well-structured and covers the scenario described in the PR objectives. It correctly defines a Prisma schema with models that could lead to foreign key constraint ambiguity and uses the
loadSchema
function to validate the schema. This ensures that the enhancements made to thePrismaSchemaGenerator
class are effectively tested against the issue of FK constraint ambiguity.However, it's important to ensure that the test case not only validates the schema loading without errors but also explicitly checks that the foreign key constraints are resolved as expected. Consider adding assertions to verify the correctness of the generated schema, especially focusing on the foreign key constraints.
Additionally, the test case currently sets
pushDb: false
andprovider: 'postgresql'
in theloadSchema
call. While this is appropriate for schema validation, ensure that the choice of database provider aligns with the intended testing environments and that any provider-specific behavior is accounted for in the test case.Overall, the test case is a valuable addition to the test suite, enhancing the coverage for foreign key constraint ambiguity handling. Just ensure to extend it with explicit assertions if needed to fully validate the enhancements.
packages/schema/src/plugins/prisma/schema-generator.ts (1)
- 459-463: The addition of the
map
argument for foreign key constraint disambiguation in thePrismaSchemaGenerator
class is a well-targeted enhancement to address the issue of foreign key constraint ambiguity. This change allows for more precise control over the selection of foreign key constraints in scenarios where ambiguity could arise, thereby improving the accuracy of the generated schema.The implementation correctly adds the
map
argument to the@relation
attribute for auxiliary opposite relation fields, using a naming convention that combines the relation field name with a_fk
suffix to denote the foreign key. This approach is logical and helps ensure that the generated schema accurately reflects the intended database structure and relationships.However, it's important to consider the potential for naming conflicts or inconsistencies that could arise from the use of this naming convention, especially in complex schemas with multiple levels of inheritance or polymorphism. Ensure that the naming convention for the
map
argument is robust enough to handle such scenarios without leading to duplicate or ambiguous foreign key names.Additionally, consider documenting the naming convention and the rationale behind the use of the
map
argument in the code comments or project documentation. This will help future maintainers and users of thePrismaSchemaGenerator
class understand the purpose and usage of this enhancement.Overall, the addition of the
map
argument is a valuable improvement to thePrismaSchemaGenerator
class, effectively addressing the issue of foreign key constraint ambiguity. Just ensure to address the considerations regarding naming conventions and documentation to enhance the maintainability and usability of this enhancement.
Summary by CodeRabbit