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 1 commit 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: 4242288

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

This PR includes changesets to release 23 packages
Name Type
@trigger.dev/build Minor
trigger.dev Minor
@trigger.dev/python Minor
d3-chat Patch
references-d3-openai-agents Patch
references-nextjs-realtime Patch
@trigger.dev/core Minor
@trigger.dev/react-hooks Minor
@trigger.dev/redis-worker Minor
@trigger.dev/rsc Minor
@trigger.dev/schema-to-json Minor
@trigger.dev/sdk Minor
@trigger.dev/database Minor
@trigger.dev/otlp-importer Minor
@internal/cache Patch
@internal/clickhouse Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/zod-worker Patch

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

Walkthrough

A new changeset file was added documenting a minor update to the @trigger.dev/build package that introduces support for Prisma's official multi-file schema structure. The internal logic of the PrismaExtension was changed to detect schema folders by checking the schema path extension, unify source/destination directory handling for schema, SQL, and migrations files, use tinyglobby to recursively discover .prisma files in schema folders, and adjust prisma generate invocation to reference either a schema folder or a single schema file. The docs for the Prisma extension were updated to recommend setting the schema option to a directory, raise the minimum Prisma version, and provide examples; no public APIs or exported entities were changed.

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 details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between da62a13 and 4242288.

📒 Files selected for processing (1)
  • .changeset/unlucky-ghosts-do.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/unlucky-ghosts-do.md
✨ Finishing Touches
🧪 Generate unit tests
  • 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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@jackall3n jackall3n force-pushed the chore/prisma-v6-multi-file-schema branch 2 times, most recently from a1d33db to fc979ec Compare August 18, 2025 15:22
@jackall3n jackall3n force-pushed the chore/prisma-v6-multi-file-schema branch from 03e4786 to 4242288 Compare August 18, 2025 15:24
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