Guide
What you get: The agent changes prisma/schema.prisma, creates a named migration with migrate dev, reuses the single PrismaClient, wraps multi-step writes in $transaction, selects only needed fields and maps P2002/P2025 to API errors. Best for Teams using Prisma who want agents to make schema changes safely..
Before you start
- A Prisma project with src/lib/db.ts exporting one client (the rules assume this path)
- A local dev database (we used SQLite)
- Fill test_command (we used npm test with Vitest)
- Cursor: .cursor/rules/prisma.mdc. Claude Code/Codex: the same text in CLAUDE.md / AGENTS.md
Worked example (Nov 14, 2026, Claude Code 2.1.318 (claude-opus-5-5); Codex 0.151.0 (gpt-5.6-sol))
Input
Prisma 6.19 + SQLite recipe API with ConflictError/NotFoundError. Task: add tags (many-to-many), a function creating a recipe with tag names atomically (duplicate slug still a ConflictError), and a list-by-tag function returning title, slug and author name, newest first.
Result
Both: a Tag model, `npx prisma migrate dev --name add_recipe_tags`, createRecipeWithTags using `prisma.$transaction(async (tx) => ...)` with tag upserts, listRecipesByTag selecting only title/slug/author.name.
Not tested in Cursor or Copilot: the rule text was saved verbatim (front matter included) as CLAUDE.md for Claude Code and AGENTS.md for Codex, the files those agents load at startup, plus a copy at its normal path. Re-run by us: tests pass (7 Claude, 6 Codex), tsc clean, prisma migrate status up to date, still one PrismaClient, no migrate reset or db push. Codex read 'commit the migration' as an order to git commit and tried to (it called it 'the project-required commit'); the sandbox's read-only .git stopped it. An installed Codex skill that also says to commit contributed. Claude Code didn't commit (the tester's global instructions forbid it). After this test, "commit the migration" became "keep the migration folder with your change": Codex read it as an instruction to run git commit.
How to check it worked
- Check prisma/migrations has a new folder and `npx prisma migrate status` is clean
- grep for `new PrismaClient` outside src/lib/db.ts
- Check git log: the agent shouldn't have committed unless you asked
Common problems
- 'commit the migration' can make an agent run git commit on its own
- Mapping P2002 to a slug conflict when the unique clash is on another column (Claude Code checked meta.target)
Log in to join the discussion.