-
-
Notifications
You must be signed in to change notification settings - Fork 788
chore: support Prisma's official multi-file schema structure #2135
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
base: main
Are you sure you want to change the base?
chore: support Prisma's official multi-file schema structure #2135
Conversation
🦋 Changeset detectedLatest commit: 4242288 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughA new changeset file was added documenting a minor update to the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type 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: 0
🧹 Nitpick comments (1)
packages/build/src/extensions/prisma.ts (1)
165-167
: Consider adding exclusion patterns for the glob search.The current glob pattern
**/*.prisma
will find all.prisma
files recursively in the schema directory. While this is generally correct, consider if certain subdirectories (likenode_modules
,dist
, or test fixtures) should be excluded to avoid including unintended schema files.If exclusion is needed, you could modify the glob call:
- const prismaFiles = await glob(["**/*.prisma"], { - cwd: this._resolvedSchemaPath - }) + const prismaFiles = await glob(["**/*.prisma"], { + cwd: this._resolvedSchemaPath, + ignore: ["**/node_modules/**", "**/dist/**", "**/test/**"] + })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (6)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
references/v3-catalog/package.json
is excluded by!references/**
references/v3-catalog/prisma/models/post.prisma
is excluded by!references/**
references/v3-catalog/prisma/models/user.prisma
is excluded by!references/**
references/v3-catalog/prisma/schema.prisma
is excluded by!references/**
references/v3-catalog/trigger.config.ts
is excluded by!references/**
📒 Files selected for processing (2)
.changeset/unlucky-ghosts-do.md
(1 hunks)packages/build/src/extensions/prisma.ts
(6 hunks)
🔇 Additional comments (4)
.changeset/unlucky-ghosts-do.md (1)
1-5
: LGTM!The changeset correctly documents the new feature as a minor version bump, which is appropriate for adding support for Prisma's official multi-file schema structure without breaking existing functionality.
packages/build/src/extensions/prisma.ts (3)
123-127
: Well-structured directory handling!The refactored directory handling with clear
prismaSourceDir
andprismaDestinationDir
variables improves code readability and maintainability. The consistent use of these variables throughout the file makes the code easier to understand and less error-prone.Also applies to: 213-214
141-143
:✅ Verification successful
Verify SQL file location requirements.
The current implementation only reads SQL files from the immediate
sql
directory usingreaddir
. If Prisma's typed SQL feature supports SQL files in subdirectories, consider using glob here as well for consistency with schema file handling.
🌐 Web query:
Does Prisma typed SQL feature support SQL files in subdirectories within the sql folder?
💡 Result:
As of Prisma version 5.19.0, the TypedSQL feature does not support organizing SQL files into subdirectories within the
prisma/sql
directory. All SQL files must reside directly within theprisma/sql
directory. This limitation is noted in the Prisma documentation:"Create a
sql
directory inside yourprisma
directory. This is where you'll write your SQL queries." (prisma.io)Attempts to structure SQL files into nested directories, such as
prisma/sql/admin/chats/getChats.sql
, are currently unsupported. This limitation has been discussed in the Prisma community, with users expressing the desire for this feature:"I would like to be able to have
/prisma/ /prisma/sql/ /prisma/sql/user/ /prisma/sql/user/getUsers.sql ...
And be able to import
import { getUsers } from '@prisma/client/sql/user' ```"However, as of now, this functionality has not been implemented. (github.com)
Therefore, to utilize TypedSQL with Prisma, ensure that all your SQL files are placed directly within the
prisma/sql
directory.Citations:
- 1: https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/typedsql?utm_source=openai
- 2: prisma/prisma#25109
Prisma TypedSQL requires flat
sql
directory—no change neededPrisma’s TypedSQL feature (as of v5.19.0) only supports SQL files placed directly in
prisma/sql
; nested subdirectories aren’t recognized. The current use ofreaddir(join(prismaSourceDir, "sql"))
correctly aligns with this limitation, so switching to a glob for recursive lookup isn’t necessary.
116-119
:✅ Verification successful
Verify the schema file extension assumption.
The implementation assumes that all Prisma schema files end with
.prisma
. The PR description raises a valid question about whether schema files could have different extensions. This should be verified against Prisma's official documentation.
🌐 Web query:
Does Prisma support schema file extensions other than .prisma for schema files?
💡 Result:
Prisma's schema files use the
.prisma
file extension, which is specific to Prisma's Schema Language (PSL). This extension is integral to Prisma's tooling and is not interchangeable with other file extensions. While Prisma introduced support for organizing schemas into multiple.prisma
files within aschema
directory (enabled via theprismaSchemaFolder
preview feature in version 5.15.0), (prisma.io) it does not support schema files with extensions other than.prisma
. Therefore, using file extensions like.graphql
or others for Prisma schema files is not supported.Citations:
Schema file extension assumption is correct.
Prisma schema files exclusively use the
.prisma
extension, so the current!this._resolvedSchemaPath.endsWith(".prisma")check accurately distinguishes between single-file schemas and schema folders. No changes are required.
a1d33db
to
fc979ec
Compare
03e4786
to
4242288
Compare
Prisma released v6.7.0, which included the official multi-file schema feature.
Prior to this version, this feature was available using the
"prismaSchemaFolder"
preview option. At the time, this feature required a./schema
folder to be created under the default./prisma
folder where "model" schemas would live (see blog).In the latest version that implementation has changed so that schema files can be placed anywhere under the
./prisma
folder (their example is under./models
), and then you specify the./prisma
directory in--schema
(not the originalprisma/schema.prisma
.✅ Checklist
Testing
<root>/references/v3-catalog
prisma files andtrigger.config.ts
and ran against docker locallypnpm link
'd the@trigger.dev/build
package to my own application and deployed to a remote instance.prismaExtension
to my own project in order to benefit from it without need to waitChangelog
[email protected]
and@prisma/[email protected]
in../v3-catalog
schema:
value does not end in.prisma
*.prisma
files usingtinyglobby
prismaExtension
documentation with a code example for how to configuration thetrigger.config.ts
fileScreenshots
💯