[TRI-5172] Compatibility with Prisma 6.6+
In Prisma 6.6.0+ they require an output path and no longer generate the Prisma client in node_modules.
This is going to cause problems with our official prisma extension which was built to deal with the old way.
It seems like the way to fix this would be to do this from their docs:
pass the the --schema option to your Prisma CLI command (e.g. prisma migrate dev --schema ./prisma/schema)
We don't pass the --schema for folders right now I don't think
Correct, you explicitly don't add the --schema flag when schemaFolder was detected
https://github.com/triggerdotdev/trigger.dev/blob/0b2eb34ea6282f72fedd2b3f677ecde633304932/packages/build/src/extensions/prisma.ts#L186-L190
i think this should fix it:
for schema folder:
commands.push(
`${binaryForRuntime(
manifest.runtime
)} node_modules/prisma/build/index.js generate --schema=./prisma/schema ${generatorFlags.join(" ")}` // Add the --schema flag for prisma@^6.6.0 compatibilty
);
for schema file
commands.push(
`${binaryForRuntime(
manifest.runtime
)} node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma ${generatorFlags.join(" ")}` // Add the --schema flag for prisma@^6.6.0 compatibilty
);
@mfts as a workaround for now, you can specify the path to the prisma schema in your package.json like this:
"prisma": {
"schema": "prisma/schema"
}
@ericallam ok cool. I'll try that.
It looks like our extension is going to need some extensive updates to fully support Prisma 6.6.0:
- Handle prisma.config.ts file if it exists, and potentially use it's values to configure the extension
- The schema location is no longer automatically detected (see their docs on this here: https://www.prisma.io/docs/orm/prisma-schema/overview/location)
- We need to stop inferring if the schema dir is being used by looking at the parent dir of the
schema.prismafile and assuming it will be namedschema
For anyone running into issues with 6.6.0, when using prismaSchemaFolder feature
- Make sure your
schema.prismafile is located insideprisma/schema, alongside your other.schemafiles. - Move your
migrationsdir into the same dir as theschema.prismafile - Make sure you specify the
schemaoption in theprismaExtensioncall to point at theschema.prismafile - Specify the "schema" path that
prisma generatewill use in yourpackage.jsonwhere yourtrigger.config.tslives to point toprisma/schema(see my comment above)
I did not manage to get his to work on my end. I did figure out another workaround though. It seems to work to use the new setup within your app and generate an old client specifically for trigger:
schema.prisma
generator client {
provider = "prisma-client"
output = "../app/generated/prisma"
}
generator triggerDevClient {
provider = "prisma-client-js"
}
trigger.config.ts
build: {
extensions: [
prismaExtension({
schema: "prisma/schema.prisma",
version: "6.6.0",
clientGenerator: "triggerDevClient",
}),
],
},
I have another workaround.
The official Prisma documentation (https://www.prisma.io/docs/orm/prisma-schema/overview/location#multi-file-prisma-schema) says you should put your *.prisma files like this:
# `migrations` and `schema.prisma` must be on the same level
.
├── migrations
├── models
│ ├── posts.prisma
│ └── users.prisma
└── schema.prisma
It also suggests that you should have an obvious "main" schema file. So, I made a workaround based on this advice.
The idea is simple, prismaExtension will only run when you deploy, so you should merge all your *.prisma files into a single file like schema.merged.prisma and set it into schema option.
Example:
- schema.merged.prisma
generator client {
provider = "prisma-client-js"
// If you use node_modules for your original deployment
// Just remove the output line, everything will work
// output = "path/to/node_modules/.prisma/client"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Company {
id String @id @default(cuid(2))
// ...
}
- trigger.config.ts
// ...
prismaExtension({
version: '6.16.1',
schema: './path/to/prisma/schema.merged.prisma',
migrate: false,
}),
// ...
You can ask AI to make the merge script and put it into CI pipeline, everything works fine.
I did not manage to get his to work on my end. I did figure out another workaround though. It seems to work to use the new setup within your app and generate an old client specifically for trigger:
schema.prisma
generator client { provider = "prisma-client" output = "../app/generated/prisma" } generator triggerDevClient { provider = "prisma-client-js" }trigger.config.ts
build: { extensions: [ prismaExtension({ schema: "prisma/schema.prisma", version: "6.6.0", clientGenerator: "triggerDevClient", }), ], },
I similarly found this to be the only thing that finally worked. I made a new generator with prisma-client-js but also had to include the binaryTargets. Hopefully this helps someone in a similar situation!
generator client {
provider = "prisma-client"
engineType = "client"
runtime = "workerd"
output = "./generated/prisma"
}
generator trigger {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
additionalFiles({ files: ["../db/prisma/schema.prisma"] }),
prismaExtension({
version: "6.19.0",
schema: "../db/prisma/schema.prisma",
clientGenerator: "trigger",
}),