kit-prisma-review
Review TypeScript code that uses Prisma Client for correctness, safety, transactions, and performance, and report findings with severity and file locations. Use when asked to review database query cod
SKILL.mdregistry/skills/prisma-review/SKILL.md
GitHubPrisma review
Report findings without modifying code unless the user asks for fixes.
1. Understand the schema and conventions
- Read
schema.prisma: models, relations,@uniqueand@@unique,@@index, optional fields, andonDeletebehavior. Note the Prisma major version, where the client is generated (@prisma/client, or a customoutputpath with theprisma-clientgenerator), and any client extensions, middleware, or driver adapters. - Find how the client is created (one shared
PrismaClient, not one per request), how transactions are written, and how errors such asP2002andP2025are handled.
2. Check each query
Correctness
updateManyanddeleteManywith an empty or missingwhereaffect every row (or fail withP2003when a required relation restricts the delete). Flag them unless that is clearly intended.findUniqueandfindFirstreturnnull; flag non-null assertions or unchecked access, and suggest an explicit check orfindUniqueOrThrow/findFirstOrThrow.updateanddeletethrowP2025when nothing matches; check callers catch it, or useupdateMany/deleteManyand checkcount.findFirstand paginatedfindManyneed a deterministicorderBy. Cursor pagination needs a unique cursor field.upsertneeds a uniquewhere; concurrent upserts can still raiseP2002.
Safety
$queryRawand$executeRawas tagged templates are parameterized.$queryRawUnsafe,$executeRawUnsafe, andPrisma.raw()with interpolated input are injection: require parameters or an allowlist for identifiers.- Without
selectoromit, queries return every scalar field, including password hashes and tokens; flag results passed straight to API responses and suggestselect,omit, or a globalomiton the client. Check tenant or owner filters are present on every query that needs them, including nested writes.
Transactions
- Writes that must succeed together belong in
prisma.$transaction([...])or an interactive$transaction(async (tx) => ...). Inside an interactive transaction every query must usetx, notprisma, and be awaited. - Avoid slow external calls inside interactive transactions; they hold a connection and can hit the transaction timeout.
Performance
- Queries in loops (N+1) should become one query with
where: { id: { in: ids } },include, or nestedselect. Deepincludetrees can fetch far more data than needed; preferselect. - Use
createManyfor many rows, and check that filtered and sorted fields have an index in the schema.
3. Verify and report
Confirm each finding by reading the query, the schema, and its callers; run the project's type check or tests when available. Report findings ordered by severity (critical, high, medium, low) with file:line, the problem, a concrete scenario, and a fix. If there are no findings, say so and list what was checked.
Examples
- Use: "Review the queries in src/orders.ts." "Check this service for Prisma mistakes."
- Skip: "Add a status field to the Order model and migrate." "Review this Kysely query." "Add an endpoint that lists orders."