trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

[TRI-5172] Compatibility with Prisma 6.6+

Open matt-aitken opened this issue 8 months ago • 8 comments

In Prisma 6.6.0+ they require an output path and no longer generate the Prisma client in node_modules.

Details here.

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

TRI-5172

matt-aitken avatar Apr 15 '25 11:04 matt-aitken

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 avatar Apr 15 '25 12:04 mfts

@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 avatar Apr 17 '25 11:04 ericallam

@ericallam ok cool. I'll try that.

mfts avatar Apr 17 '25 11:04 mfts

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.prisma file and assuming it will be named schema

ericallam avatar Apr 17 '25 12:04 ericallam

For anyone running into issues with 6.6.0, when using prismaSchemaFolder feature

  • Make sure your schema.prisma file is located inside prisma/schema, alongside your other .schema files.
  • Move your migrations dir into the same dir as the schema.prisma file
  • Make sure you specify the schema option in the prismaExtension call to point at the schema.prisma file
  • Specify the "schema" path that prisma generate will use in your package.json where your trigger.config.ts lives to point to prisma/schema (see my comment above)

ericallam avatar Apr 17 '25 13:04 ericallam

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",
      }),
    ],
  },

manuelbiermann avatar Apr 23 '25 15:04 manuelbiermann

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.

whchi avatar Sep 14 '25 09:09 whchi

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",
  }),

jjrise avatar Nov 10 '25 17:11 jjrise