Skip to content
Back to skills

Prisma

ASecurity

Prisma schema design, migrations, client generation and query patterns. Use when changing a Prisma schema, writing a migration, or querying with Prisma Client.

  • 80 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 28, 2026
ai-agentstypescriptgosqlnodedatabase

Works with

  • cli

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned October 5, 2026

npx -y skills add monkilabs/opencastle --skill prisma-database --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prisma?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Prisma
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/monkilabs-prisma/badge)](https://www.skillsdirectory.com/skills/monkilabs-prisma)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: prisma-database
description: "Prisma schema design, migrations, client generation and query patterns. Use when changing a Prisma schema, writing a migration, or querying with Prisma Client."
---

# Prisma Database

Project schema and connection details: `.opencastle/stack/database-config.md`. Docs: https://www.prisma.io/docs

## Migration rules

- `npx prisma migrate dev` in development only — **never in production**; it can reset data. CI/production uses `npx prisma migrate deploy`.
- Inspect `prisma/migrations/<timestamp>/migration.sql` before applying. Destructive operations (drops, column rewrites) need an explicit backfill step added to the migration.
- **Never edit an already-applied migration file** — the checksum is recorded and will fail. Write a corrective migration instead.
- `npx prisma generate` after every schema change; a stale client silently mismatches the DB. `npx prisma db push` skips migration history entirely — prototyping only.

## Schema gotchas

- Use `cuid()` / `uuid()` for IDs, not serial increments, in anything distributed.
- Renaming a field without matching `@map`/`@@map` produces a *column drop plus add*, not a rename. Check both when renaming.
- Add `@@index` explicitly on frequently queried columns — the schema does not imply them.
- Write `@relation` explicitly, including `onDelete` (e.g. `onDelete: Cascade`); leaving it implicit means the delete behavior is whatever the connector defaults to.
- Include `createdAt @default(now())` and `updatedAt @updatedAt` for auditability.

## Client and queries

Hot reload in dev creates a new `PrismaClient` per reload and exhausts the connection pool. Use the global singleton:

```typescript
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
export const prisma = globalForPrisma.prisma ?? new PrismaClient();
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
```

Use `select` for narrow reads, `include` for relations, `prisma.$transaction` for multi-step writes. Catch error code **`P2002`** for unique-constraint violations and handle it rather than letting it surface as a 500.

Other commands: `prisma studio` (visual editor), `prisma db pull` (introspect), `prisma db seed`, `prisma validate`, `prisma format`.

Files in this skill

  • REFERENCE.md1.3 KB
  • SKILL.md3.3 KB
  • config.ts688 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.