Prisma 6 Migration Guide
This skill guides you through upgrading from Prisma 5 to Prisma 6, handling all breaking changes systematically to prevent runtime failures and type errors.
- Buffer → Uint8Array: Bytes fields now use Uint8Array instead of Buffer
- Implicit m-n PKs: Many-to-many join tables now use compound primary keys
- NotFoundError → P2025: Error class removed, use error code checking
- Reserved Keywords:
async, await, using are now reserved model/field names
Attempting to use Prisma 6 without these updates causes type errors, runtime failures, and migration issues.
Phase 1: Pre-Migration Assessment
Identify all Bytes fields in schema
- Use Grep to find
@db.ByteA, Bytes field types
- List all files using Buffer operations on Bytes fields
Find implicit many-to-many relationships
- Search schema for relation fields without explicit join tables
- Identify models with
@relation without relationName
Locate NotFoundError usage
- Grep for
NotFoundError imports and usage
- Find error handling that checks error class
Check for reserved keywords
- Search schema for models/fields named
async, await, using
Phase 2: Schema Migration
Update reserved keywords in schema
- Rename any models/fields using reserved words
- Update all references in application code
Generate migration for implicit m-n changes
- Run
npx prisma migrate dev --name v6-implicit-mn-pks
- Review generated SQL for compound primary key changes
Phase 3: Code Migration
Update Buffer → Uint8Array conversions
- Replace
Buffer.from() with TextEncoder
- Replace
.toString() with TextDecoder
- Update type annotations from Buffer to Uint8Array
Update NotFoundError handling
- Replace error class checks with P2025 code checks
- Use
isPrismaClientKnownRequestError type guard
Test all changes
- Run existing tests
- Verify Bytes field operations
- Confirm error handling works correctly
Phase 4: Validation
Run TypeScript compiler
- Verify no type errors remain
- Check all Buffer references resolved
Run database migrations
- Apply migrations to test database
- Verify compound PKs created correctly
Runtime testing
- Test Bytes field read/write operations
- Verify error handling catches not-found cases
- Confirm implicit m-n queries work
Quick Reference
Breaking Changes Summary:
| Change |
Before |
After |
| Buffer API |
Buffer.from(), .toString() |
TextEncoder, TextDecoder |
| Error Handling |
error instanceof NotFoundError |
error.code === 'P2025' |
| Implicit m-n PK |
Auto-increment id |
Compound PK (A, B) |
| Reserved Words |
async, await, using allowed |
Must use @map() |
Migration Command:
npx prisma migrate dev --name v6-upgrade
Validation Commands:
npx tsc --noEmit
npx prisma migrate status
npm test
MUST:
- Backup production database before migration
- Test migration in development/staging first
- Review auto-generated migration SQL
- Update all Buffer operations to TextEncoder/TextDecoder
- Replace all NotFoundError checks with P2025 code checks
- Run TypeScript compiler to verify no type errors
SHOULD:
- Create helper functions for common error checks
- Use
@map() when renaming reserved keywords
- Document breaking changes in commit messages
- Update team documentation about Prisma 6 patterns
NEVER:
- Run migrations directly in production without testing
- Skip TypeScript compilation check
- Leave Buffer references in code (causes type errors)
- Use NotFoundError (removed in Prisma 6)
- Use
async, await, using as model/field names without @map()
After completing migration:
TypeScript Compilation:
- Run:
npx tsc --noEmit
- Expected: Zero type errors
- If fails: Check remaining Buffer references, NotFoundError usage
Database Migration Status:
- Run:
npx prisma migrate status
- Expected: All migrations applied
- If fails: Apply pending migrations with
npx prisma migrate deploy
Runtime Testing:
- Test Bytes field write/read cycle
- Verify error handling catches P2025 correctly
- Test implicit m-n relationship queries
- Confirm no runtime errors in production-like environment
Performance Check:
- Verify query performance unchanged
- Check connection pool behavior
- Monitor error rates in logs
Rollback Readiness:
- Document rollback steps
- Keep Prisma 5 migration snapshot
- Test rollback procedure in staging
References
For detailed migration guides and examples:
- Breaking Changes Details: See
references/breaking-changes.md for complete API migration patterns, SQL examples, and edge cases
- Migration Examples: See
references/migration-examples.md for real-world migration scenarios with before/after code
- Migration Checklist: See
references/migration-checklist.md for step-by-step migration tasks
- Troubleshooting Guide: See
references/troubleshooting.md for common migration issues and solutions
For framework-specific migration patterns:
- Next.js Integration: Consult Next.js plugin for App Router-specific Prisma 6 patterns
- Serverless Deployment: See CLIENT-serverless-config skill for Prisma 6 + Lambda/Vercel
For error handling patterns:
- Error Code Reference: See TRANSACTIONS-error-handling skill for comprehensive P-code handling
1---2name: upgrading-to-prisma-63description: Migrate from Prisma 5 to Prisma 6 handling breaking changes including Buffer to Uint8Array, implicit m-n PK changes, NotFoundError to P2025, and reserved keywords. Use when upgrading Prisma, encountering Prisma 6 type errors, or migrating legacy code.4---5
6# Prisma 6 Migration Guide
7
8This skill guides you through upgrading from Prisma 5 to Prisma 6, handling all breaking changes systematically to prevent runtime failures and type errors.
9
10---
11
12<role>
13This skill teaches Claude how to migrate Prisma 5 codebases to Prisma 6 following the official migration guide, addressing breaking changes in Buffer API, implicit many-to-many relationships, error handling, and reserved keywords.
14</role>
15
16<when-to-activate>
17This skill activates when:
18- User mentions "Prisma 6", "upgrade Prisma", "migrate to Prisma 6"
19- Encountering Prisma 6 type errors related to Bytes fields
20- Working with Prisma migrations or schema changes during upgrades
21- User reports NotFoundError issues after upgrading
22- Reserved keyword conflicts appear (`async`, `await`, `using`)
23</when-to-activate>
24
25<overview>
26Prisma 6 introduces four critical breaking changes that require code updates:
27
281. **Buffer → Uint8Array**: Bytes fields now use Uint8Array instead of Buffer
292. **Implicit m-n PKs**: Many-to-many join tables now use compound primary keys
303. **NotFoundError → P2025**: Error class removed, use error code checking
314. **Reserved Keywords**: `async`, `await`, `using` are now reserved model/field names
32
33Attempting to use Prisma 6 without these updates causes type errors, runtime failures, and migration issues.
34</overview>
35
36<workflow>
37## Migration Workflow
38
39**Phase 1: Pre-Migration Assessment**
40
411. Identify all Bytes fields in schema
42 - Use Grep to find `@db.ByteA`, `Bytes` field types
43 - List all files using Buffer operations on Bytes fields
44
452. Find implicit many-to-many relationships
46 - Search schema for relation fields without explicit join tables
47 - Identify models with `@relation` without `relationName`
48
493. Locate NotFoundError usage
50 - Grep for `NotFoundError` imports and usage
51 - Find error handling that checks error class
52
534. Check for reserved keywords
54 - Search schema for models/fields named `async`, `await`, `using`
55
56**Phase 2: Schema Migration**
57
581. Update reserved keywords in schema
59 - Rename any models/fields using reserved words
60 - Update all references in application code
61
622. Generate migration for implicit m-n changes
63 - Run `npx prisma migrate dev --name v6-implicit-mn-pks`
64 - Review generated SQL for compound primary key changes
65
66**Phase 3: Code Migration**
67
681. Update Buffer → Uint8Array conversions
69 - Replace `Buffer.from()` with TextEncoder
70 - Replace `.toString()` with TextDecoder
71 - Update type annotations from Buffer to Uint8Array
72
732. Update NotFoundError handling
74 - Replace error class checks with P2025 code checks
75 - Use `isPrismaClientKnownRequestError` type guard
76
773. Test all changes
78 - Run existing tests
79 - Verify Bytes field operations
80 - Confirm error handling works correctly
81
82**Phase 4: Validation**
83
841. Run TypeScript compiler
85 - Verify no type errors remain
86 - Check all Buffer references resolved
87
882. Run database migrations
89 - Apply migrations to test database
90 - Verify compound PKs created correctly
91
923. Runtime testing
93 - Test Bytes field read/write operations
94 - Verify error handling catches not-found cases
95 - Confirm implicit m-n queries work
96</workflow>
97
98## Quick Reference
99
100**Breaking Changes Summary:**
101
102| Change | Before | After |
103|--------|--------|-------|
104| Buffer API | `Buffer.from()`, `.toString()` | `TextEncoder`, `TextDecoder` |
105| Error Handling | `error instanceof NotFoundError` | `error.code === 'P2025'` |
106| Implicit m-n PK | Auto-increment `id` | Compound PK `(A, B)` |
107| Reserved Words | `async`, `await`, `using` allowed | Must use `@map()` |
108
109**Migration Command:**
110```bash
111npx prisma migrate dev --name v6-upgrade
112```
113
114**Validation Commands:**
115```bash
116npx tsc --noEmit
117npx prisma migrate status
118npm test
119```
120
121<constraints>
122## Migration Guidelines
123
124**MUST:**
125- Backup production database before migration
126- Test migration in development/staging first
127- Review auto-generated migration SQL
128- Update all Buffer operations to TextEncoder/TextDecoder
129- Replace all NotFoundError checks with P2025 code checks
130- Run TypeScript compiler to verify no type errors
131
132**SHOULD:**
133- Create helper functions for common error checks
134- Use `@map()` when renaming reserved keywords
135- Document breaking changes in commit messages
136- Update team documentation about Prisma 6 patterns
137
138**NEVER:**
139- Run migrations directly in production without testing
140- Skip TypeScript compilation check
141- Leave Buffer references in code (causes type errors)
142- Use NotFoundError (removed in Prisma 6)
143- Use `async`, `await`, `using` as model/field names without `@map()`
144</constraints>
145
146<validation>
147## Post-Migration Validation
148
149After completing migration:
150
1511. **TypeScript Compilation:**
152 - Run: `npx tsc --noEmit`
153 - Expected: Zero type errors
154 - If fails: Check remaining Buffer references, NotFoundError usage
155
1562. **Database Migration Status:**
157 - Run: `npx prisma migrate status`
158 - Expected: All migrations applied
159 - If fails: Apply pending migrations with `npx prisma migrate deploy`
160
1613. **Runtime Testing:**
162 - Test Bytes field write/read cycle
163 - Verify error handling catches P2025 correctly
164 - Test implicit m-n relationship queries
165 - Confirm no runtime errors in production-like environment
166
1674. **Performance Check:**
168 - Verify query performance unchanged
169 - Check connection pool behavior
170 - Monitor error rates in logs
171
1725. **Rollback Readiness:**
173 - Document rollback steps
174 - Keep Prisma 5 migration snapshot
175 - Test rollback procedure in staging
176</validation>
177
178## References
179
180For detailed migration guides and examples:
181
182- **Breaking Changes Details**: See `references/breaking-changes.md` for complete API migration patterns, SQL examples, and edge cases
183- **Migration Examples**: See `references/migration-examples.md` for real-world migration scenarios with before/after code
184- **Migration Checklist**: See `references/migration-checklist.md` for step-by-step migration tasks
185- **Troubleshooting Guide**: See `references/troubleshooting.md` for common migration issues and solutions
186
187For framework-specific migration patterns:
188- **Next.js Integration**: Consult Next.js plugin for App Router-specific Prisma 6 patterns
189- **Serverless Deployment**: See CLIENT-serverless-config skill for Prisma 6 + Lambda/Vercel
190
191For error handling patterns:
192- **Error Code Reference**: See TRANSACTIONS-error-handling skill for comprehensive P-code handling