fix(build/prisma): support custom schema directories and Prisma 6.6+ …
…compatibility
This change makes the Prisma build extension work with any schema directory name (e.g. "schema", "models", "db", "prisma-schemas") and ensures compatibility with Prisma 6.6+.
Configuration:
Always point the schema option to your main schema file, not the folder:
prismaExtension({ version: "6.18.0", schema: "../../packages/prisma/src/models/schema.prisma", // ← Point to the file migrate: false, })
The main schema file can have any name (schema.prisma, main.prisma, etc.) and can live in any directory. It does NOT have to be called "schema.prisma".
How it works:
- Auto-detects a "schema folder" by checking the parent directory of the schema file for multiple .prisma files. If 2+ .prisma files exist in that directory, we treat it as a folder-based schema setup.
- For folder-based schemas (multiple files), all .prisma files in that directory are copied to ./prisma/schema/ in the build output. For Prisma >= 6.6, we run: prisma generate --schema=./prisma/schema For older Prisma versions, we omit the --schema flag for backwards compatibility.
- For single-file schemas (only one .prisma file in the directory), the file is copied to ./prisma/schema.prisma and we run: prisma generate --schema=./prisma/schema.prisma
Examples:
Folder-based (multiple .prisma files): packages/prisma/src/models/
├── schema.prisma ← Point to this in config
├── user.prisma
└── post.prisma
Single file: packages/prisma/
└── schema.prisma ← Point to this in config
Backwards compatibility:
- Older Prisma versions (< 6.6) continue to work without the --schema flag for folder setups
- Single-file setups are unaffected
- No breaking changes
Closes #1926
Closes #
✅ Checklist
- [ ] I have followed every step in the contributing guide
- [ ] The PR title follows the convention.
- [ ] I ran and tested the code works
Testing
[Describe the steps you took to test this change]
Changelog
[Short description of what has changed]
Screenshots
[Screenshots]
💯
⚠️ No Changeset found
Latest commit: da6fa1f94bbbec129ea2c07ea6d6ea82ec89fbec
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Walkthrough
This change modifies Prisma schema detection and command generation in the build extension. The schema folder detection mechanism shifts from a simple heuristic to dynamic scanning for multiple .prisma files. Version-conditional logic is introduced to pass the --schema flag for Prisma 6.6+ during client generation. Schema path handling is refactored to remove redundancy. The changes maintain backward compatibility for older Prisma versions and non-schema-folder workflows.
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20–25 minutes
-
Version detection logic: Verify the version check condition (
major > 6 || (major == 6 && minor >= 6)) is correctly implemented and tested -
Multiple code paths: The conditional
--schemaflag is applied in both the schema-folder and standard workflow branches; ensure consistency across paths -
Schema folder detection: Review the dynamic detection logic that scans for multiple
.prismafiles to ensure it handles edge cases (empty directories, single-file scenarios, symlinks) -
Backward compatibility: Confirm that older Prisma versions and non-schema-folder workflows retain expected behavior without the
--schemaflag
Pre-merge checks and finishing touches
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title accurately describes the main changes: support for custom schema directories and Prisma 6.6+ compatibility. |
| Description check | ✅ Passed | The description provides comprehensive context including behavior changes, configuration guidance, examples, and backward compatibility notes, though testing and changelog sections remain as placeholders. |
| Linked Issues check | ✅ Passed | The code changes fully address issue #1926 requirements: dynamic schema detection, conditional --schema flag for Prisma 6.6+, and support for custom schema directories. |
| Out of Scope Changes check | ✅ Passed | All changes to the Prisma extension are directly scoped to the linked issue objectives; no extraneous modifications are present. |
✨ 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
This should be fixed now in 4.1.1