Copy-paste Claude Code prompts for Prisma — schema design, safe migrations, seed scripts, and avoiding the N+1 trap with include vs select.
Prisma is well-documented enough that Claude handles schema edits cleanly. The risks are around performance (include vs select) and migration safety. The prompts below address both.
Add a Subscription model to schema.prisma.
Fields:
- id String @id @default(uuid()) @db.Uuid
- account Account @relation(fields: [accountId], references: [id], onDelete: Cascade)
- accountId String @db.Uuid
- status SubStatus
- amountCents Int
- currency String @db.Char(3)
- currentPeriodEnd DateTime
- canceledAt DateTime?
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
Plus an enum SubStatus { TRIALING ACTIVE PAST_DUE CANCELED }.
Constraints:
- Index on (accountId, status). Index on (currentPeriodEnd) for the billing job query.
- Add the reverse relation on Account: subscriptions Subscription[].
- Read schema.prisma first to match formatting (spacing, comment style).
- Generate the migration with prisma migrate dev --create-only --name add_subscription.
Do NOT run migrate. Output the SQL it generates so I can review.
The /api/orders endpoint uses prisma.order.findMany with include: { customer:
true, items: true, payments: true }. That's pulling everything.
Refactor to select only the fields the response actually returns. Read the
endpoint's response serializer first.
Constraints:
- Replace include with select { ...scalarFields, customer: { select: {...} },
items: { select: {...} } }.
- Only include the fields used by the serializer.
- If the serializer accesses customer.email, include only id, name, email.
- Print a before/after count of bytes selected (estimate: roughly fields × rows).
- DO NOT change the response shape — only the underlying query.
Rename Order.amt to Order.amountCents safely. Table has ~5M rows in prod.
Produce 4 migrations:
1. add_order_amount_cents — adds nullable column amountCents.
2. backfill_order_amount_cents — RunPython-equivalent: prisma client raw SQL
"UPDATE \"Order\" SET \"amountCents\" = amt" — but in batches of 10000
to avoid lock-table-too-long.
3. set_order_amount_cents_not_null — adds the NOT NULL constraint.
4. drop_order_amt — drops the old column.
Output one prisma migration .sql per step in prisma/migrations/. Update the
Prisma schema in step 3 (the model uses amountCents from there forward).
Deploy plan: 1 → wait, deploy app code reading both → 2 → 3 → app reads only
amountCents → 4.
## Prisma policy
- Prisma 6, Postgres 16, prisma-extension-accelerate disabled (we use direct).
- Schema files: schema.prisma main + schema files under prisma/schemas/.
- Migration policy: never edit migration SQL after it's been deployed.
Renames are expand/contract, not AlterColumn.
- Querying: prefer select over include. Document the reason inline.
- Seed: prisma/seed.ts. Idempotent — use upsert.
Related: refactoring prompts.