prisma
Skill6 starsChanged 4 months agoMITView on GitHub
TypeScript and Prisma ORM best practices for schema design, type-safe queries, migrations, and error handling. Use when writing Prisma schemas, building database access layers, or debugging query performance in TypeScript projects.
- Reads credentials
7 other projects use a version of this.
Adopted by
Most recently taken up by
- G1Joshi/Agent-Skillstheir own version, first seen Oct 13, 2026
- Alteriom/ai-dev-skillstheir own version, first seen Oct 11, 2026
- juanquijandria/prisma-harnesstheir own version, first seen Oct 9, 2026
- Mindrally/skillstheir own version, first seen Oct 8, 2026
- trycompai/comptheir own version, first seen Oct 8, 2026
- elie222/inbox-zerotheir own version, first seen Oct 8, 2026
Used with
Projects with it also use react.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
VercelSkillreact
React renderer for json-render that turns JSON specs into React components. Use when working with @json-render/react, building React UIs from JSON, creating component catalogs, or rendering AI-generated specs.
Also in 3 projects that use this
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- elie222/inbox-zero★ 13ksame name
- trycompai/comp★ 2.1ksame name
- Mindrally/skills★ 275same name
- G1Joshi/Agent-Skills★ 15same name
- YepAPI/skills★ 8same name
- juanquijandria/prisma-harness★ 2same name
- Alteriom/ai-dev-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository23 other files it gives its agents.
- adhdSkill
- adversarial-challengeSkill
- ai-systems-reviewSkill
- asd-ste100Skill
- brandingSkill
- brutal-truthSkill
- code-reviewSkill
- create-issueSkill
- css-resetSkill
- deep-researchSkill
- depth-uiSkill
- engineering-judgmentSkill
- human-writingSkill
- just-stopSkill
- mini-loopSkill
- model-benchSkill
- openrouterSkill
- pushbackSkill
- react-componentSkill
- shut-up-and-driveSkill
- subagentSkill
- token-maxxingSkill
- vibe-auditSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. 0 are common, 7 are distinctive, and 6 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
7
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Enums vs client imports: Import from the generated enums.ts in client/shared code.
- Distinctive: line 14
Repository pattern: Keep data access logic separate from business logic.
- Distinctive: line 16
Never modify existing migrations: Treat migrations as append-only history.
- Distinctive: line 60
Use domain-driven model names.
- Distinctive: line 63
Use Prisma's native type decorators for database-level precision.
- Very specific: line 67
N+1: Use nested include or select instead of looping with separate queries.
- Very specific: line 68
Pagination: Use take and skip; add a cursor-based approach for large datasets.
- Very specific: line 69
Field selection: Use select to fetch only needed fields.
- Very specific: line 86
Use descriptive names: prisma migrate dev --name add_user_email_index.
- Distinctive: line 88
Never edit existing migration files — create a new migration instead.
- Distinctive: line 89
Keep migrations idempotent where possible.
- Very specific: line 95
Do multi-record writes use $transaction?
- Distinctive: line 98
Do migrations have descriptive names and remain unmodified after creation?
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
prisma
Ensures Prisma code is type-safe, performant, and architecturally clean — covering the non-obvious patterns that trip up even experienced developers.
Core Principles
- One PrismaClient per process. Multiple instances create multiple connection pools and exhaust your database connection limit.
- Enums vs client imports. Import from the generated
enums.tsin client/shared code; import fromclient.tsonly in server-side code. Never importclient.tsin client components. - Repository pattern. Keep data access logic separate from business logic. Create repository modules for complex query sets.
- Transactions for multi-step writes. Any operation that modifies more than one record should use
$transaction. - Never modify existing migrations. Treat migrations as append-only history.
When to Use
- Writing or reviewing Prisma schema models
- Building or refactoring a database access layer
- Debugging N+1 queries or performance regressions
- Setting up Prisma in a new project (especially Next.js)
Implementation Guide
Client Setup (Singleton)
The hot-reload guard is required in Next.js — without it, dev mode creates a new PrismaClient on every file change and exhausts connections:
// lib/prisma.ts
import { PrismaClient } from "@prisma/client";
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
export const prisma =
globalForPrisma.prisma ?? new PrismaClient();
if (process.env.NODE_ENV !== "production")
globalForPrisma.prisma = prisma;Enums vs Client Imports
// ✅ Client component or shared validation code
import { Role, Status } from "@prisma/client/enums";
// ✅ Server-side only (API routes, server components, background jobs)
import { prisma } from "@/lib/prisma";
import type { User } from "@prisma/client";
// ❌ Never in client components
import { PrismaClient } from "@prisma/client";Schema Design
- Use domain-driven model names. Keep schemas normalized and DRY.
- Declare all relations explicitly with
@relation. - Implement soft delete via
deletedAt DateTime?— never hard-delete records that may be referenced. - Use Prisma's native type decorators for database-level precision.
Queries & Performance
- N+1: Use nested
includeorselectinstead of looping with separate queries. - Pagination: Use
takeandskip; add acursor-based approach for large datasets. - Field selection: Use
selectto fetch only needed fields; avoid over-fetching with blanketinclude. - Join strategy:
relationLoadStrategy("join"or"query") is available but requires enabling therelationJoinspreview feature flag."join"uses a singleLATERAL JOIN;"query"sends one query per table and joins at the application level.
Error Handling
Catch Prisma-specific errors at the repository boundary:
PrismaClientKnownRequestError— structured DB errors. Checkerror.code:P2002— unique constraint violationP2025— record not found (replaces the removedNotFoundErrorfrom Prisma 5)
PrismaClientUnknownRequestError— unstructured DB errorsPrismaClientValidationError— invalid query shape (usually a type error)
Provide user-friendly messages upstream; log the full error with context for debugging.
Migrations
- Use descriptive names:
prisma migrate dev --name add_user_email_index. - Review generated SQL before applying to production.
- Never edit existing migration files — create a new migration instead.
- Keep migrations idempotent where possible.
Review Checklist
- Is there a single PrismaClient instance with the hot-reload guard in place?
- Are enums imported from
enums.tsin any client or shared code? - Do multi-record writes use
$transaction? - Are N+1 patterns avoided (no DB calls inside loops)?
- Are
PrismaClientKnownRequestErrorcodes handled at the repository boundary? - Do migrations have descriptive names and remain unmodified after creation?
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

