-
-
Notifications
You must be signed in to change notification settings - Fork 880
fix(build/prisma): support custom schema directories and Prisma 6.6+ … #2655
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?
fix(build/prisma): support custom schema directories and Prisma 6.6+ … #2655
Conversation
…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 triggerdotdev#1926
|
WalkthroughThis 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 Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/build/src/extensions/prisma.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations
Files:
packages/build/src/extensions/prisma.ts
🧠 Learnings (1)
📚 Learning: 2025-07-18T17:49:24.468Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T17:49:24.468Z
Learning: Applies to internal-packages/database/**/*.{ts,tsx} : We use prisma in internal-packages/database for our database interactions using PostgreSQL
Applied to files:
packages/build/src/extensions/prisma.ts
🧬 Code graph analysis (1)
packages/build/src/extensions/prisma.ts (1)
packages/build/src/extensions/index.ts (1)
binaryForRuntime(16-16)
| const [major, minor] = version.split(".").map(Number); | ||
| const requiresSchemaFlag = major > 6 || (major === 6 && minor >= 6); | ||
|
|
||
| commands.push( | ||
| `${binaryForRuntime( | ||
| manifest.runtime | ||
| )} node_modules/prisma/build/index.js generate ${generatorFlags.join(" ")}` // Don't add the --schema flag or this will fail | ||
| `${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate${ | ||
| requiresSchemaFlag ? " --schema=./prisma/schema" : "" | ||
| } ${generatorFlags.join(" ")}` |
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.
Fix version parsing before gating --schema.
If version comes from a range (e.g. ^6.6.0, workspace:*), version.split(".").map(Number) yields NaN, so requiresSchemaFlag stays false and we skip --schema. On Prisma 6.6+ folder builds that omission breaks prisma generate. Extract the numeric major/minor safely before deciding.
- const [major, minor] = version.split(".").map(Number);
- const requiresSchemaFlag = major > 6 || (major === 6 && minor >= 6);
+ const versionMatch = version.match(/(\d+)(?:\.(\d+))?/);
+ const major = versionMatch ? Number(versionMatch[1]) : undefined;
+ const minor = versionMatch && versionMatch[2] ? Number(versionMatch[2]) : 0;
+ const requiresSchemaFlag =
+ major !== undefined && (major > 6 || (major === 6 && minor >= 6));🤖 Prompt for AI Agents
In packages/build/src/extensions/prisma.ts around lines 190 to 196, the current
version parsing uses version.split(".").map(Number) which yields NaN for range
specifiers like "^6.6.0" or "workspace:*", so the requiresSchemaFlag is
incorrectly false; update the parsing to first extract the numeric major and
minor via a regex (e.g. match the first occurrence of digits separated by a dot
like /(\d+)\.(\d+)/), convert those capture groups to numbers with safe fallback
(0) and then compute requiresSchemaFlag as major > 6 || (major === 6 && minor >=
6); this ensures --schema is included for Prisma 6.6+ even when version strings
contain ranges or non-numeric prefixes.
…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
schemaoption 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:
Examples:
Folder-based (multiple .prisma files): packages/prisma/src/models/
Single file: packages/prisma/
Backwards compatibility:
Closes #1926
Closes #
✅ Checklist
Testing
[Describe the steps you took to test this change]
Changelog
[Short description of what has changed]
Screenshots
[Screenshots]
💯