Skip to content

Commit da6fa1f

Browse files
committed
fix(build/prisma): support custom schema directories and Prisma 6.6+ 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
1 parent 9fdf91a commit da6fa1f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

packages/build/src/extensions/prisma.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ export class PrismaExtension implements BuildExtension {
112112

113113
context.logger.debug(`PrismaExtension is generating the Prisma client for version ${version}`);
114114

115-
const usingSchemaFolder = dirname(this._resolvedSchemaPath).endsWith("schema");
115+
// Auto-detect schema folder by checking for multiple .prisma files
116+
const schemaDir = dirname(this._resolvedSchemaPath);
117+
const prismaFilesInDir = await readdir(schemaDir)
118+
.then((files) => files.filter((file) => file.endsWith(".prisma")))
119+
.catch(() => []);
120+
const usingSchemaFolder = prismaFilesInDir.length > 1;
116121

117122
const commands: string[] = [];
118123

@@ -155,13 +160,11 @@ export class PrismaExtension implements BuildExtension {
155160
}
156161

157162
if (usingSchemaFolder) {
158-
const schemaDir = dirname(this._resolvedSchemaPath);
159-
160163
prismaDir = dirname(schemaDir);
161164

162165
context.logger.debug(`Using the schema folder: ${schemaDir}`);
163166

164-
// Find all the files in schemaDir that end with .prisma (excluding the schema.prisma file)
167+
// Find all the files in schemaDir that end with .prisma
165168
const prismaFiles = await readdir(schemaDir).then((files) =>
166169
files.filter((file) => file.endsWith(".prisma"))
167170
);
@@ -183,10 +186,14 @@ export class PrismaExtension implements BuildExtension {
183186
await cp(source, destination);
184187
}
185188

189+
// Prisma 6.6+ requires --schema flag for schema folders
190+
const [major, minor] = version.split(".").map(Number);
191+
const requiresSchemaFlag = major > 6 || (major === 6 && minor >= 6);
192+
186193
commands.push(
187-
`${binaryForRuntime(
188-
manifest.runtime
189-
)} node_modules/prisma/build/index.js generate ${generatorFlags.join(" ")}` // Don't add the --schema flag or this will fail
194+
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js generate${
195+
requiresSchemaFlag ? " --schema=./prisma/schema" : ""
196+
} ${generatorFlags.join(" ")}`
190197
);
191198
} else {
192199
prismaDir = dirname(this._resolvedSchemaPath);

0 commit comments

Comments
 (0)