Skip to content

Fix prismaExtension schema folder detection#3746

Closed
duongynhi000005-oss wants to merge 1 commit into
triggerdotdev:mainfrom
duongynhi000005-oss:fix/prisma-schema-folder-2654
Closed

Fix prismaExtension schema folder detection#3746
duongynhi000005-oss wants to merge 1 commit into
triggerdotdev:mainfrom
duongynhi000005-oss:fix/prisma-schema-folder-2654

Conversation

@duongynhi000005-oss
Copy link
Copy Markdown

Fixes #2654. Detect schema folders by contents, not folder name, and pass --schema=./prisma/schema for schema-folder builds.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

⚠️ No Changeset found

Latest commit: c8b8961

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

@github-actions
Copy link
Copy Markdown
Contributor

Hi @duongynhi000005-oss, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this May 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e4aae7ff-7be3-4a47-a795-75ef7a8053cf

📥 Commits

Reviewing files that changed from the base of the PR and between 37eeaa3 and c8b8961.

📒 Files selected for processing (1)
  • packages/build/src/extensions/prisma.ts

Walkthrough

The PR modifies Prisma schema handling in the build extension. The schema folder detection now checks the schema directory for additional .prisma files to determine if it is a multi-file schema setup, replacing the previous path-suffix heuristic. The basename utility is imported to support this logic. The TypedSQL Prisma client generation command is updated to include an explicit --schema=./prisma/schema argument.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 No test coverage for schema folder detection logic

There are no test files for the Prisma extension (glob for *prisma*test* and *prisma*spec* returned no results). Given the complexity of the three-way detection logic (isMultiFileSchema vs usingSchemaFolder vs single-file) and the various downstream effects (migrations, TypedSQL, generate commands), this code would benefit from unit tests covering each detection branch. The CLAUDE.md testing guidelines emphasize tests should live beside source files.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 547 to +551
const usingSchemaFolder =
!isMultiFileSchema && dirname(this._resolvedSchemaPath).endsWith("schema");
!isMultiFileSchema &&
(await readdir(schemaDir)).some(
(file) => file.endsWith(".prisma") && file !== basename(this._resolvedSchemaPath)
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Widened usingSchemaFolder detection causes incorrect prismaDir when .prisma siblings exist in prisma/ directly

The new usingSchemaFolder detection on lines 547-551 checks for any sibling .prisma files in the same directory, but the downstream usingSchemaFolder branch at line 640 assumes schema files live in a subdirectory (e.g., prisma/schema/*.prisma) and computes prismaDir = dirname(schemaDir) — going up one level.

When a user has multiple .prisma files directly in prisma/ (e.g., prisma/schema.prisma + prisma/models.prisma, a valid Prisma 6.7+ setup) and specifies schema: "prisma/schema.prisma", the new detection triggers a false positive: schemaDir = <root>/prisma, so prismaDir = dirname(schemaDir) = <root> (the project root). This causes:

  1. Migrations silently skipped: migrationsDir is computed as join(prismaDir, "migrations") = <root>/migrations (prisma.ts:722), but actual migrations are at <root>/prisma/migrations. The existsSync check at line 736 fails and logs a warning, but the deployment proceeds without running migrations.
  2. TypedSQL fails: prismaDirForSql is computed as dirname(dirname(resolvedSchemaPath)) = <root> (prisma.ts:579), so SQL files are looked for at <root>/sql/ instead of <root>/prisma/sql/.

The old heuristic (dirname(...).endsWith("schema")) would not have matched this case and correctly fell through to the single-file else branch.

Prompt for agents
The usingSchemaFolder detection now matches any directory containing sibling .prisma files, but the downstream logic (prismaDir = dirname(schemaDir) at line 640, prismaDirForSql = dirname(dirname(...)) at line 579) assumes the schema files are in a subdirectory like prisma/schema/*.prisma — not directly in prisma/.

To fix this, you need to either:

1. Restrict the detection to only match when the schema file is in a subdirectory of the prisma root (i.e., the schema file's parent directory is NOT the typical prisma root). For example, check that schemaDir itself is not the directory containing package.json or prisma config, or that schemaDir's basename is a known schema folder name.

2. Or, adjust the downstream code in the usingSchemaFolder branch to correctly handle the case where schema files live directly in the prisma directory (not in a subdirectory). This would mean prismaDir should be set to schemaDir (not dirname(schemaDir)), and prismaDirForSql should go up only one level.

Option 1 is safer as it preserves the existing downstream assumptions. A possible approach: keep the new sibling-file check but also verify that the schema file is at least 2 levels deep from the project root (i.e., the parent of schemaDir should not be the working directory), or check that schemaDir is a subdirectory of a directory that itself contains other prisma-related artifacts (like migrations/).
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 666 to 672
commands.push(
`${binaryForRuntime(
manifest.runtime
)} node_modules/prisma/build/index.js generate ${generatorFlags.join(" ")}` // Don't add the --schema flag or this will fail
)} node_modules/prisma/build/index.js generate --schema=./prisma/schema ${generatorFlags.join(
" "
)}`
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚩 The --schema=./prisma/schema flag addition contradicts the removed comment

The old code at line 666 had a comment: // Don't add the --schema flag or this will fail. The PR removes this comment and adds --schema=./prisma/schema. This is likely correct for modern Prisma versions (6.7+ and 5.x with prismaSchemaFolder preview) since the files ARE copied to output/prisma/schema/. However, if any users are on older Prisma versions that don't support --schema with a directory path, this would break. Worth confirming that the minimum supported Prisma version handles this flag correctly.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

bug: Prisma 6.6+ Schema Folder Bug: Missing --schema Flag

1 participant