From da6fa1f94bbbec129ea2c07ea6d6ea82ec89fbec Mon Sep 17 00:00:00 2001 From: Cameron Mema <30882523+cameronmema@users.noreply.github.com> Date: Wed, 5 Nov 2025 06:01:20 -0500 Subject: [PATCH] fix(build/prisma): support custom schema directories and Prisma 6.6+ compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/build/src/extensions/prisma.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/build/src/extensions/prisma.ts b/packages/build/src/extensions/prisma.ts index b67adc7efc..4850a99822 100644 --- a/packages/build/src/extensions/prisma.ts +++ b/packages/build/src/extensions/prisma.ts @@ -112,7 +112,12 @@ export class PrismaExtension implements BuildExtension { context.logger.debug(`PrismaExtension is generating the Prisma client for version ${version}`); - const usingSchemaFolder = dirname(this._resolvedSchemaPath).endsWith("schema"); + // Auto-detect schema folder by checking for multiple .prisma files + const schemaDir = dirname(this._resolvedSchemaPath); + const prismaFilesInDir = await readdir(schemaDir) + .then((files) => files.filter((file) => file.endsWith(".prisma"))) + .catch(() => []); + const usingSchemaFolder = prismaFilesInDir.length > 1; const commands: string[] = []; @@ -155,13 +160,11 @@ export class PrismaExtension implements BuildExtension { } if (usingSchemaFolder) { - const schemaDir = dirname(this._resolvedSchemaPath); - prismaDir = dirname(schemaDir); context.logger.debug(`Using the schema folder: ${schemaDir}`); - // Find all the files in schemaDir that end with .prisma (excluding the schema.prisma file) + // Find all the files in schemaDir that end with .prisma const prismaFiles = await readdir(schemaDir).then((files) => files.filter((file) => file.endsWith(".prisma")) ); @@ -183,10 +186,14 @@ export class PrismaExtension implements BuildExtension { await cp(source, destination); } + // Prisma 6.6+ requires --schema flag for schema folders + 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(" ")}` ); } else { prismaDir = dirname(this._resolvedSchemaPath);