Claude Code Prompts for Prisma

Copy-paste Claude Code prompts for Prisma — schema design, safe migrations, seed scripts, and avoiding the N+1 trap with include vs select.

💥 50p impulse-buy: Power Prompts PDF (first 10 buyers) 30 battle-tested Claude Code prompts · 8-page PDF · paste into CLAUDE.md and never re-type a prompt again · 50p impulse-buy, no commitment

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.

Prompt 1 — Schema model with relations + indexes

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.

Prompt 2 — Replace include with select to avoid wide reads

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.

Prompt 3 — Expand/contract migration for renaming a column

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.

CLAUDE.md for Prisma

## 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.

Frequently asked questions

Will Claude write Prisma 5 or 6?
Defaults to Prisma 6 (preview-flag-free typed sql, multi-file schema). Pin the version in CLAUDE.md if you're on 5.x.
Does Claude understand the N+1 with include?
Yes if you point at it. Default behaviour: include can fetch a large object. Use select with a nested select to bound the field set.
How do I get safe migrations from Claude?
Use the migration prompt below — it forces expand/contract sequencing rather than a single destructive AlterColumn.

Free tools

Cost Calculator → API Cookbook → Diff Summarizer → Skills Browser →

More examples

Claude API Python QuickstartClaude API Node.js / TypeScript QuickstartClaude API Streaming in PythonClaude API Streaming in Node.js / TypeScriptClaude API Tool Use in PythonClaude API Tool Use in Node.js / TypeScript