Commit c042ac9
authored
feat: Support prisma >6.7 in standard starter (#457)
## Context
* Updates the standard starter
* to use prisma 6.7
* to use the new `prisma-client` generator: prisma will now generate code to a gitignored `generated/prisma` dir
* to use the new `queryCompiler` flag to reduce the size of the WASM (by around ~350KB)
---
## 🔁 Prisma >6.7 migration guide for existing projects
Prisma introduced a new client generator ([`prisma-client`](https://www.prisma.io/docs/orm/prisma-schema/overview/generators#prisma-client-early-access)) that lets us generate a client specific to Cloudflare workers (via workerd runtime) and ESM - this makes for much simpler and less error prone Vite integration.
This guide walks you through upgrading an existing RedwoodSDK Standard Starter project.
### **1\. ✅ Update Dependencies**
Update the following packages in your package.json:
```
- "@prisma/adapter-d1": "~6.5.0",
- "@prisma/client": "~6.5.0",
- "prisma": "~6.5.0",
+ "@prisma/adapter-d1": "~6.8.2",
+ "@prisma/client": "~6.8.2",
+ "prisma": "~6.8.2",
```
Also upgrade wrangler to at least ^4.16.0.
```
- "wrangler": "^4.14.1"
+ "wrangler": "^4.16.0"
```
* * * * *
### **2\. 🧬 Update **
### **schema.prisma**
Change the generator block to use the new prisma-client:
```
-generator client {
- provider = "prisma-client-js"
- previewFeatures = ["driverAdapters"]
- output = "../node_modules/.prisma/client"
+generator client {
+ provider = "prisma-client"
+ runtime = "workerd"
+ moduleFormat = "esm"
+ generatedFileExtension = "ts"
+ importFileExtension = "ts"
+ output = "../generated/prisma"
+ previewFeatures = ["queryCompiler", "driverAdapters"]
}
```
* * * * *
### **3\. 🗂️ Adjust TypeScript Paths**
In tsconfig.json:
```
- ".prisma/*": ["./node_modules/.prisma/*"]
+"@/*": ["./src/*"],
+ "@generated/*": ["./generated/*"]
```
Then update imports from `@prisma/client` to `@/db.`
* * * * *
### **4\. 🛠️ Refactor DB Client Usage**
Replace your `src/db.ts` with the latest in the standard starter:
https://github.com/redwoodjs/sdk/blob/main/starters/standard/src/db.ts
* * * * *
### 5\. 📁 Add to **.gitignore**
```
+generated/
```
* * * * *
### **6\. 📦 Re-generate Client**
After updating schema.prisma:
```
pnpm prisma generate
```
* * * * *
### **7\. 🧪 Test Everything**
Check your queries work in development and deployments.
---
## Notes
### Steps taken
https://gist.github.com/justinvdm/24a9f316f7c5148be852c4660e5f0481
### Update: 21 May 2025
- Submitted PR for the relevant fix required in `@cloudflare/vite-plugin`: cloudflare/workers-sdk#9322
- Got this PR working on both prisma <6.7 and >6.7 (assuming cloudflare/workers-sdk#9322 fix is in and PR upgraded to use it)
- See [action log](https://gist.github.com/justinvdm/24a9f316f7c5148be852c4660e5f0481) for more detail on steps taken
### Update: 19 May 2025
- **Goal**: ==Upgrade to Prisma >=6.7, remove Prisma-specific Vite logic from RedwoodSDK, avoid WASM if possible, and maintain backwards compatibility.
- **Steps Taken**:
- Upgraded to Prisma 6.8.2 with queryCompiler and driverAdapters.
- Tried out different vite configurations and aliases to target new Prisma client structure.
- Tested various entry points (edge.js, index.js, wasm.js) and generation configs
- Validated new `prisma-client` generator for `workerd` + `esm `output.
- **Current Status**: Generated client works and loads in dev with SDK changes. DB client instantiation succeeds. Queries fail due to WASM module resolution error during runtime.
- **Blocking Issue**: Cloudflare's Vite plugin fails to resolve Prisma's WASM module path, likely due to pnpm's path format (`__`) interfering with Cloudflare's module detection regex. Investigating patch to regex logic in `@cloudflare/vite-plugin`.
- **Findings**:
- **Not WASM free (yet?):** Prisma is not WASM free yet, but they're gradually moving the components out of rust into ts. There's still a **1.66MB** wasm file we must work with. Previously it was **2MB**.
- **Cloudflare's plugin appears to mangle WASM imports** when the file path includes double underscores (__), likely due to greedy regex
- **Switching to Prisma's new ESM generator is promising** for us to avoid complexities - e.g. we can avoid having to get optimizeDeps to esm-ify the `require`s in the generated prisma client (though we'll still need some logic for <6.7)
- **Next Step**: Investigate patch, then corresponding PR for Cloudflare's Vite plugin to fix its WASM module resolution regex handling for __ in paths.1 parent 60f7fd8 commit c042ac9
File tree
11 files changed
+4696
-6058
lines changed- sdk/src/vite
- starters
- minimal
- standard
- prisma
- src
- scripts
11 files changed
+4696
-6058
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
| 8 | + | |
11 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | | - | |
11 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
13 | 21 | | |
14 | 22 | | |
15 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | | - | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| 21 | + | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
0 commit comments