Skip to content

Commit 15fef91

Browse files
authored
feat(build): update prisma extension to work with generated clients and rust-free clients (#2689)
* prisma extension fixes WIP * More prisma stuff * more prisma stuff * remove changelog * upgrade github workflows to use node 20.19 because installing prisma@7 breaks with lower versions * Don't use generate for the prisma reference projects * make sure it works if no mode is passed in
1 parent e2a703b commit 15fef91

File tree

80 files changed

+2502
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2502
-94
lines changed

.changeset/six-vans-rhyme.md

Lines changed: 383 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,383 @@
1+
---
2+
"@trigger.dev/build": patch
3+
---
4+
5+
The `prismaExtension` has been completely redesigned to support multiple Prisma versions and deployment strategies. This update introduces **three distinct modes** to handle the evolving Prisma ecosystem, from legacy setups to the upcoming Prisma 7.
6+
7+
**Highlights:**
8+
9+
- 🎯 Three modes: Legacy, Engine-Only, and Modern
10+
- 🎉 **NEW:** Support for `prisma.config.ts` files (Legacy Mode)
11+
- 🔍 **NEW:** Enhanced version detection with filesystem fallback
12+
13+
## Breaking Changes
14+
15+
⚠️ **MIGRATION REQUIRED**: The `prismaExtension` now requires an explicit `mode` parameter. Existing configurations without a `mode` will need to be updated.
16+
17+
**Note:** All other existing options remain backward compatible. The new `configFile` option is optional and doesn't affect existing setups using the `schema` option.
18+
19+
### Before (Old API)
20+
21+
```ts
22+
import { prismaExtension } from "@trigger.dev/build/extensions/prisma";
23+
24+
extensions: [
25+
prismaExtension({
26+
schema: "prisma/schema.prisma",
27+
migrate: true,
28+
typedSql: true,
29+
directUrlEnvVarName: "DATABASE_URL_UNPOOLED",
30+
}),
31+
];
32+
```
33+
34+
### After (New API)
35+
36+
```ts
37+
import { prismaExtension } from "@trigger.dev/build/extensions/prisma";
38+
39+
extensions: [
40+
prismaExtension({
41+
mode: "legacy", // ← MODE IS NOW REQUIRED
42+
schema: "prisma/schema.prisma",
43+
migrate: true,
44+
typedSql: true,
45+
directUrlEnvVarName: "DATABASE_URL_UNPOOLED",
46+
}),
47+
];
48+
```
49+
50+
## New Features
51+
52+
### 1. Legacy Mode
53+
54+
**Use when:** You're using Prisma 6.x or earlier with the `prisma-client-js` provider.
55+
56+
**Features:**
57+
58+
- Automatic `prisma generate` during deployment
59+
- Supports single-file schemas (`prisma/schema.prisma`)
60+
- Supports multi-file schemas (Prisma 6.7+, directory-based schemas)
61+
- **NEW:** Supports Prisma config files (`prisma.config.ts`) via `@prisma/config` package
62+
- Migration support with `migrate: true`
63+
- TypedSQL support with `typedSql: true`
64+
- Custom generator selection
65+
- Handles Prisma client versioning automatically (with filesystem fallback detection)
66+
- Automatic extraction of schema and migrations paths from config files
67+
68+
**Schema Configuration:**
69+
70+
```prisma
71+
generator client {
72+
provider = "prisma-client-js"
73+
previewFeatures = ["typedSql"]
74+
}
75+
76+
datasource db {
77+
provider = "postgresql"
78+
url = env("DATABASE_URL")
79+
directUrl = env("DATABASE_URL_UNPOOLED")
80+
}
81+
```
82+
83+
**Extension Configuration:**
84+
85+
```ts
86+
// Single-file schema
87+
prismaExtension({
88+
mode: "legacy",
89+
schema: "prisma/schema.prisma",
90+
migrate: true,
91+
typedSql: true,
92+
directUrlEnvVarName: "DATABASE_URL_UNPOOLED",
93+
});
94+
95+
// Multi-file schema (Prisma 6.7+)
96+
prismaExtension({
97+
mode: "legacy",
98+
schema: "./prisma", // ← Point to directory
99+
migrate: true,
100+
typedSql: true,
101+
directUrlEnvVarName: "DATABASE_URL_UNPOOLED",
102+
});
103+
```
104+
105+
**Tested Versions:**
106+
107+
- Prisma 6.14.0 ✅
108+
- Prisma 6.7.0+ (multi-file schema support) ✅
109+
- Prisma 5.x ✅
110+
111+
---
112+
113+
### 2. Engine-Only Mode
114+
115+
**Use when:** You have a custom Prisma client output path and want to manage `prisma generate` yourself.
116+
117+
**Features:**
118+
119+
- Only installs Prisma engine binaries (no client generation)
120+
- Automatic version detection from `@prisma/client`
121+
- Manual override of version and binary target
122+
- Minimal overhead - just ensures engines are available
123+
- You control when and how `prisma generate` runs
124+
125+
**Schema Configuration:**
126+
127+
```prisma
128+
generator client {
129+
provider = "prisma-client-js"
130+
output = "../src/generated/prisma"
131+
// Ensure the "debian-openssl-3.0.x" binary target is included for deployment to the trigger.dev cloud
132+
binaryTargets = ["native", "debian-openssl-3.0.x"]
133+
}
134+
135+
datasource db {
136+
provider = "postgresql"
137+
url = env("DATABASE_URL")
138+
directUrl = env("DATABASE_URL_UNPOOLED")
139+
}
140+
```
141+
142+
**Extension Configuration:**
143+
144+
```ts
145+
// Auto-detect version
146+
prismaExtension({
147+
mode: "engine-only",
148+
});
149+
150+
// Explicit version (recommended for reproducible builds)
151+
prismaExtension({
152+
mode: "engine-only",
153+
version: "6.19.0",
154+
});
155+
```
156+
157+
**Important Notes:**
158+
159+
- You **must** run `prisma generate` yourself (typically in a prebuild script)
160+
- Your schema **must** include the correct `binaryTargets` for deployment to the trigger.dev cloud. The binary target is `debian-openssl-3.0.x`.
161+
- The extension sets `PRISMA_QUERY_ENGINE_LIBRARY` and `PRISMA_QUERY_ENGINE_SCHEMA_ENGINE` environment variables to the correct paths for the binary targets.
162+
163+
**package.json Example:**
164+
165+
```json
166+
{
167+
"scripts": {
168+
"prebuild": "prisma generate",
169+
"dev": "trigger dev",
170+
"deploy": "trigger deploy"
171+
}
172+
}
173+
```
174+
175+
**Tested Versions:**
176+
177+
- Prisma 6.19.0 ✅
178+
- Prisma 6.16.0+ ✅
179+
180+
---
181+
182+
### 3. Modern Mode
183+
184+
**Use when:** You're using Prisma 6.16+ with the new `prisma-client` provider (with `engineType = "client"`) or preparing for Prisma 7.
185+
186+
**Features:**
187+
188+
- Designed for the new Prisma architecture
189+
- Zero configuration required
190+
- Automatically marks `@prisma/client` as external
191+
- Works with Prisma 7 beta releases & Prisma 7 when released
192+
- You manage client generation (like engine-only mode)
193+
194+
**Schema Configuration (Prisma 6.16+ with engineType):**
195+
196+
```prisma
197+
generator client {
198+
provider = "prisma-client"
199+
output = "../src/generated/prisma"
200+
engineType = "client"
201+
previewFeatures = ["views"]
202+
}
203+
204+
datasource db {
205+
provider = "postgresql"
206+
url = env("DATABASE_URL")
207+
directUrl = env("DATABASE_URL_UNPOOLED")
208+
}
209+
```
210+
211+
**Schema Configuration (Prisma 7):**
212+
213+
```prisma
214+
generator client {
215+
provider = "prisma-client"
216+
output = "../src/generated/prisma"
217+
}
218+
219+
datasource db {
220+
provider = "postgresql"
221+
}
222+
```
223+
224+
**Extension Configuration:**
225+
226+
```ts
227+
prismaExtension({
228+
mode: "modern",
229+
});
230+
```
231+
232+
**Prisma Config (Prisma 7):**
233+
234+
```ts
235+
// prisma.config.ts
236+
import { defineConfig, env } from "prisma/config";
237+
import "dotenv/config";
238+
239+
export default defineConfig({
240+
schema: "prisma/schema.prisma",
241+
migrations: {
242+
path: "prisma/migrations",
243+
},
244+
datasource: {
245+
url: env("DATABASE_URL"),
246+
},
247+
});
248+
```
249+
250+
**Important Notes:**
251+
252+
- You **must** run `prisma generate` yourself
253+
- Requires Prisma 6.16.0+ or Prisma 7 beta
254+
- The new `prisma-client` provider generates plain TypeScript (no Rust binaries)
255+
- Requires database adapters (e.g., `@prisma/adapter-pg` for PostgreSQL)
256+
257+
**Tested Versions:**
258+
259+
- Prisma 6.16.0 with `engineType = "client"`
260+
- Prisma 6.20.0-integration-next.8 (Prisma 7 beta) ✅
261+
262+
---
263+
264+
## Migration Guide
265+
266+
### From Old prismaExtension to Legacy Mode
267+
268+
If you were using the previous `prismaExtension`, migrate to **Legacy Mode**:
269+
270+
```ts
271+
// Old
272+
prismaExtension({
273+
schema: "prisma/schema.prisma",
274+
migrate: true,
275+
});
276+
277+
// New
278+
prismaExtension({
279+
mode: "legacy", // ← Add this
280+
schema: "prisma/schema.prisma",
281+
migrate: true,
282+
});
283+
```
284+
285+
### From Managing Your Own Prisma Setup
286+
287+
If you previously handled Prisma generation yourself and just needed engine binaries, use **Engine-Only Mode**:
288+
289+
```ts
290+
prismaExtension({
291+
mode: "engine-only",
292+
version: "6.19.0", // Match your @prisma/client version
293+
});
294+
```
295+
296+
### Preparing for Prisma 7
297+
298+
If you want to adopt the new Prisma architecture, use **Modern Mode**:
299+
300+
1. Update your schema to use `prisma-client` provider
301+
2. Add database adapters to your dependencies
302+
3. Configure the extension:
303+
304+
```ts
305+
prismaExtension({
306+
mode: "modern",
307+
});
308+
```
309+
310+
---
311+
312+
## Version Compatibility Matrix
313+
314+
| Prisma Version | Recommended Mode | Notes |
315+
| ---------------- | --------------------- | -------------------------------------------- |
316+
| < 5.0 | Legacy | Older Prisma versions |
317+
| 5.0 - 6.15 | Legacy | Standard Prisma setup |
318+
| 6.7+ | Legacy | Multi-file schema support |
319+
| 6.16+ | Engine-Only or Modern | Modern mode requires `engineType = "client"` |
320+
| 6.20+ (7.0 beta) | Modern | Prisma 7 with new architecture |
321+
322+
---
323+
324+
## Prisma Config File Support (Prisma 6+)
325+
326+
**NEW:** Legacy Mode now supports loading configuration from a `prisma.config.ts` file using the official `@prisma/config` package.
327+
328+
**Use when:** You want to use Prisma's new config file format (Prisma 6+) to centralize your Prisma configuration.
329+
330+
**Benefits:**
331+
332+
- Single source of truth for Prisma configuration
333+
- Automatic extraction of schema location and migrations path
334+
- Type-safe configuration with TypeScript
335+
- Works seamlessly with Prisma 7's config-first approach
336+
337+
**prisma.config.ts:**
338+
339+
```ts
340+
import { defineConfig, env } from "prisma/config";
341+
import "dotenv/config";
342+
343+
export default defineConfig({
344+
schema: "prisma/schema.prisma",
345+
migrations: {
346+
path: "prisma/migrations",
347+
},
348+
datasource: {
349+
url: env("DATABASE_URL"),
350+
directUrl: env("DATABASE_URL_UNPOOLED"),
351+
},
352+
});
353+
```
354+
355+
**trigger.config.ts:**
356+
357+
```ts
358+
import { prismaExtension } from "@trigger.dev/build/extensions/prisma";
359+
360+
prismaExtension({
361+
mode: "legacy",
362+
configFile: "./prisma.config.ts", // ← Use config file instead of schema
363+
migrate: true,
364+
directUrlEnvVarName: "DATABASE_URL_UNPOOLED", // For migrations
365+
});
366+
```
367+
368+
**What gets extracted:**
369+
370+
- `schema` - The schema file or directory path
371+
- `migrations.path` - The migrations directory path (if specified)
372+
373+
**Note:** Either `schema` or `configFile` must be specified, but not both.
374+
375+
**When to use which:**
376+
377+
| Use `schema` option | Use `configFile` option |
378+
| ---------------------------- | --------------------------------- |
379+
| Standard Prisma setup | Using Prisma 6+ with config files |
380+
| Single or multi-file schemas | Preparing for Prisma 7 |
381+
| No `prisma.config.ts` file | Centralized configuration needed |
382+
| Simple setup | Want migrations path in config |
383+

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: ⎔ Setup node
3737
uses: buildjet/setup-node@v4
3838
with:
39-
node-version: 20.11.1
39+
node-version: 20.19.0
4040

4141
- name: 📥 Download deps
4242
run: pnpm install --frozen-lockfile --filter trigger.dev...

0 commit comments

Comments
 (0)