Skip to content

Conversation

@dhritcu
Copy link
Contributor

@dhritcu dhritcu commented Oct 9, 2025

Resolves #291

Summary by CodeRabbit

  • Bug Fixes
    • Corrected Prisma schema generation to ignore inherited mapping attributes from base models, preventing unintended propagation of @@Map. This eliminates duplicate or invalid mappings in generated schemas, reducing validation and migration errors and producing more predictable output.

ymc9 added 30 commits June 17, 2025 13:08
merge dev to main (3.0.0-alpha.4)
merge dev to main (v3.0.0-alpha.6)
merge dev to main (v3.0.0-alpha.13)
merge dev to main (v3.0.0-alpha.14)
merge dev to main (v3.0.0-alpha.15)
merge dev to main (v3.0.0-alpha.16)
merge dev to main (v3.0.0-alpha.17)
merge dev to main (v3.0.0-alpha.18)
merge dev to main (v3.0.0-alpha.19)
merge dev to main (v3.0.0-alpha.21)
merge dev to main (v3.0.0-alpha.22)
merge dev to main (v3.0.0-alpha.23)
merge dev to main (v3.0.0-alpha.24)
merge dev to main (v3.0.0-alpha.25)
merge dev to main (v3.0.0-alpha.26)
merge dev to main (v3.0.0-alpha.27)
merge dev to main (v3.0.0-alpha.29)
@coderabbitai
Copy link

coderabbitai bot commented Oct 9, 2025

Walkthrough

The PrismaSchemaGenerator now filters model attributes to exclude inherited @@Map attributes from base models. A new private helper, isInheritedMapAttribute, detects map attributes originating from a different container. Attribute generation uses this guard to include only Prisma attributes relevant to the current model context.

Changes

Cohort / File(s) Summary
Prisma schema generation filtering
packages/sdk/src/prisma/prisma-schema-generator.ts
Added isInheritedMapAttribute helper and updated attribute processing in generateModel to skip inherited @@Map attributes; ensures only current-context Prisma attributes are emitted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitched my whiskers, sifted the hay,
Skipped the maps that wandered away—
Only the local glyphs may stay.
In Prisma fields I hop and play,
Guarding context, come what may.
Thump! Clean schemas lead the way. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly summarizes the core change of preventing inherited map attributes from being applied by indicating “don’t inherit inherited map attribute,” which aligns directly with the code updates filtering out inherited @@Map attributes in the PrismaSchemaGenerator. It concisely reflects the fix without introducing unrelated details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/sdk/src/prisma/prisma-schema-generator.ts (1)

190-197: Implementation correctly identifies inherited @@map attributes.

The logic properly checks if an attribute is inherited (different container) and is specifically a @@map attribute. The nullish coalescing operator safely handles cases where the reference is unresolved.

Consider adding JSDoc to explain why only @@map is filtered among inherited attributes:

+    /**
+     * Checks if an attribute is an inherited @@map attribute.
+     * @@map attributes define table names and should not be inherited
+     * from base models, as each model should have its own table mapping.
+     */
     private isInheritedMapAttribute(attr: DataModelAttribute, contextModel: DataModel) {
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35a9e0d and 0bf7a4f.

📒 Files selected for processing (1)
  • packages/sdk/src/prisma/prisma-schema-generator.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{packages,samples,tests}/**

📄 CodeRabbit inference engine (CLAUDE.md)

Place packages only under packages/, samples/, or tests/

Files:

  • packages/sdk/src/prisma/prisma-schema-generator.ts
🧬 Code graph analysis (1)
packages/sdk/src/prisma/prisma-schema-generator.ts (2)
packages/language/src/generated/ast.ts (4)
  • DataModelAttribute (395-400)
  • DataModelAttribute (402-402)
  • DataModel (377-387)
  • DataModel (389-389)
packages/language/src/ast.ts (1)
  • DataModel (49-54)
🔇 Additional comments (1)
packages/sdk/src/prisma/prisma-schema-generator.ts (1)

174-176: Filtering logic correctly excludes inherited @@map; no other inherited model-level attributes detected.

@ymc9 ymc9 changed the base branch from main to dev October 9, 2025 18:13
Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for making the fix, @dhritcu

@ymc9 ymc9 merged commit 831cb66 into zenstackhq:dev Oct 9, 2025
5 of 6 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.

[BUG] When using extend, the @@map is inherited as well

2 participants