Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jackall3n
Copy link

@jackall3n jackall3n commented Jun 1, 2025

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 original prisma/schema.prisma.

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

  • Updated the <root>/references/v3-catalog prisma files and trigger.config.ts and ran against docker locally
  • pnpm link'd the @trigger.dev/build package to my own application and deployed to a remote instance.
  • Copied the updated prismaExtension to my own project in order to benefit from it without need to wait

Changelog

  • Bumped [email protected] and @prisma/[email protected] in ../v3-catalog
  • Use schema folder if schema: value does not end in .prisma
    • Is this enough? Is it possible to have a schema file with a different extension?
  • Retrieve all *.prisma files using tinyglobby
  • Updated the prismaExtension documentation with a code example for how to configuration the trigger.config.ts file

Screenshots

Screenshot 2025-06-02 at 09 30 05

💯

Copy link

changeset-bot bot commented Jun 1, 2025

🦋 Changeset detected

Latest commit: bf6c407

The changes in this PR will be included in the next version bump.

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

Copy link
Contributor

coderabbitai bot commented Jun 1, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new changeset file was added to document a minor update to the @trigger.dev/build package, specifically introducing support for Prisma's official multi-file schema structure. The internal logic of the PrismaExtension class was revised to better handle scenarios where the Prisma schema is organized as a directory containing multiple .prisma files. The detection of schema type now checks the file extension, and file operations for schema, SQL, and migrations directories have been updated to consistently use source and destination paths. The code now uses the tinyglobby package to recursively find all .prisma files in schema folders. The Prisma generate command was updated to correctly reference the schema folder or file. The documentation for the Prisma extension was also updated to clarify usage of the multi-file schema feature, update the Prisma version requirement, and provide improved examples. No public APIs or exported entities were changed.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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/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 (like node_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

📥 Commits

Reviewing files that changed from the base of the PR and between ff157e5 and 4373e98.

⛔ 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 and prismaDestinationDir 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 using readdir. 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 the prisma/sql directory. This limitation is noted in the Prisma documentation:

"Create a sql directory inside your prisma 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:


Prisma TypedSQL requires flat sql directory—no change needed

Prisma’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 of readdir(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 a schema directory (enabled via the prismaSchemaFolder 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.

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.

1 participant