Skip to content

Conversation

@cameronmema
Copy link

…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]

💯

…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
@changeset-bot
Copy link

changeset-bot bot commented Nov 5, 2025

⚠️ No Changeset found

Latest commit: da6fa1f

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

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 --schema flag 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 .prisma files 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 --schema flag

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9fdf91a and da6fa1f.

📒 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)

Comment on lines +190 to +196
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(" ")}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

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.

[TRI-5172] Compatibility with Prisma 6.6+

1 participant