prisma-patterns

Implements Prisma ORM schema design, transactions, pagination, and migration patterns for TypeScript backends.

5|15|Updated Jul 8, 2026
One-click install
npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill prisma-patterns-clfigueiredo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: prisma-patterns
Source: https://github.com/clfigueiredo/hermes-infra-skills/tree/main/.hermes/skills/curso-hermes/prisma-patterns
Command: npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill prisma-patterns-clfigueiredo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Prisma ORM has non-obvious traps that cause production bugs: updateMany returning counts instead of records, interactive transactions timing out after 5 seconds, migrate dev resetting databases, and @updatedAt silently skipping bulk writes. This Skill provides production-tested patterns and anti-pattern warnings so you avoid these pitfalls when building TypeScript backends. ## Core Features & Use Cases - Schema & Query Patterns: ID strategy selection (cuid vs uuid vs autoincrement), include vs select guidance, N+1 prevention, and cursor-based pagination with stable ordering. - Transaction & Migration Safety: Correct $transaction form selection, expand-and-contract migrations for breaking changes, and migrate deploy vs migrate dev rules for CI/CD. - Serverless & Error Handling: PrismaClient singleton with globalThis caching, connection_limit tuning for Vercel/Lambda, and P2002/P2025/P2003 error translation to domain errors. - Use Case: You are adding a NOT NULL column to a live users table. The Skill walks you through the three-step expand-and-contract migration (add nullable column, backfill data, add constraint) so you never lock the table or drop data in production. ## Quick Start Ask the agent to review your Prisma schema and service layer for common traps like updateMany return values, missing updatedAt on bulk writes, and unsafe migrate dev usage.

Frequently Asked Questions about prisma-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement cursor pagination in Prisma?▼

Fetch limit + 1 rows with a cursor on the id field and pop the extra row to detect hasNextPage without a count query. Always add a unique secondary orderBy field like id to prevent unstable pagination when rows share the same timestamp.

Why does Prisma updateMany not return the updated records?▼

updateMany returns only { count: n }, never the affected rows, and the same applies to deleteMany. To get the records, first query the matching IDs with findMany, run the bulk update, then fetch those IDs again.

Does @updatedAt work with updateMany in Prisma?▼

No, @updatedAt is set automatically only on update and upsert operations. Bulk writes via updateMany leave it stale, so you must set updatedAt: new Date() explicitly in the data payload.

Why does my Prisma transaction fail with 'Transaction already closed'?▼

Interactive $transaction callbacks time out after 5 seconds by default, and external calls like sending email inside the callback exceed that limit. Move external calls outside the transaction or raise the timeout option only when genuinely needed.

Is prisma migrate dev safe to run in production?▼

No, migrate dev detects schema drift and may prompt to reset the database, dropping all data. Use migrate deploy in CI/CD and shared environments, and reserve migrate dev for local solo development only.

How do I configure Prisma for serverless like Vercel or Lambda?▼

Set connection_limit=1 and pool_timeout directly in the DATABASE_URL query string so each serverless instance opens a single connection. For high concurrency, route through an external pooler like PgBouncer with pgbouncer=true in the URL.