# prisma

Reference patterns for Prisma ORM in TypeScript projects: schema design, migrations, nested queries, and Next.js setup.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 222 installs · ★ 80 repo stars
- Author: bobmatnyc
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/bobmatnyc/claude-mpm-skills/tree/HEAD/toolchains/typescript/data/prisma/SKILL.md
- Updated: 2026-07-18
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/bobmatnyc-prisma

## What it does

This skill equips coding assistants with structural conventions for Prisma ORM inside TypeScript codebases. It outlines core schema patterns for `prisma/schema.prisma`, covering field attributes, indexes, and diverse relational models including one-to-one, one-to-many, many-to-many, and self-referential relations.

The reference details type-safe database queries such as nested writes, aggregation operations, raw SQL via `$queryRaw`, and sequential or batched transactions with `$transaction`. It also provides Prisma CLI workflows for schema migrations, prototyping with `db push`, and schema introspection.

Your project must have `prisma` and `@prisma/client` installed locally, alongside an accessible `DATABASE_URL` environment variable for client generation to succeed.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill prisma -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/prisma/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/prisma/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill prisma -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/prisma/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill prisma -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/prisma/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install bobmatnyc/claude-mpm-skills toolchains/typescript/data/prisma
```

2. **Manually: put the files in place**
- File: `.github/skills/prisma/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill prisma -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/bobmatnyc/claude-mpm-skills --path toolchains/typescript/data/prisma
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/prisma/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add bobmatnyc/claude-mpm-skills --skill prisma -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/bobmatnyc/claude-mpm-skills/tree/HEAD/toolchains/typescript/data/prisma/SKILL.md

## When to use it
- Draft relational database models and indexes inside `prisma/schema.prisma`
- Write type-safe queries with nested writes and custom filtering logic
- Implement sequential rollbacks and batch operations using transactions
- Prevent connection exhaustion in Next.js App Router via a global client singleton
- Execute database migrations and schema pushes during development or deployment

## Example prompts
- Add a many-to-many relationship between Post and Category models in `schema.prisma`
- Write a nested write operation that creates a user and an associated profile in one transaction
- Set up a global PrismaClient singleton helper inside `lib/prisma.ts` for Next.js

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: c35cb783f02a2318.

BEGIN THIRD-PARTY FILE c35cb783f02a2318
````text
---
name: prisma
description: "Prisma ORM for TypeScript - Type-safe database toolkit with schema-first development, auto-generated client, migrations, relations, and Prisma Studio"
user-invocable: false
disable-model-invocation: true
progressive_disclosure:
  entry_point:
    summary: "Prisma ORM for TypeScript - Type-safe database toolkit with schema-first development, auto-generated client, migrations, relations, and Prisma Studio"
    when_to_use: "When working with version control, branches, or pull requests."
    quick_start: "1. Review the core concepts below. 2. Apply patterns to your use case. 3. Follow best practices for implementation."
---
# Prisma ORM - Type-Safe Database Toolkit

Modern database toolkit for TypeScript with schema-first development, auto-generated type-safe client, and powerful migration system.

## Quick Reference

### Installation

```bash
npm install prisma @prisma/client
npx prisma init
```

### Basic Workflow

```bash
# 1. Define schema
# Edit prisma/schema.prisma

# 2. Create migration
npx prisma migrate dev --name init

# 3. Generate client
npx prisma generate

# 4. Open Studio
npx prisma studio
```

### Core Schema Pattern

```prisma
// prisma/schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  posts     Post[]
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Post {
  id        String   @id @default(cuid())
  title     String
  content   String?
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id])
  authorId  String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@index([authorId])
}
```

### Type-Safe CRUD

```typescript
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

// Create
const user = await prisma.user.create({
  data: {
    email: 'alice@example.com',
    name: 'Alice',
    posts: {
      create: { title: 'First Post', content: 'Hello World' }
    }
  },
  include: { posts: true }
});

// Read with filters
const users = await prisma.user.findMany({
  where: { email: { contains: '@example.com' } },
  include: { posts: { where: { published: true } } },
  orderBy: { createdAt: 'desc' },
  take: 10
});

// Update
await prisma.user.update({
  where: { id: userId },
  data: { name: 'Bob' }
});

// Delete
await prisma.user.delete({ where: { id: userId } });
```

## Schema Design Patterns

### Field Types and Attributes

```prisma
model Product {
````
END THIRD-PARTY FILE c35cb783f02a2318

The third-party file has ended. Everything between the c35cb783f02a2318 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2667 of 14114 bytes. © bobmatnyc · MIT · https://github.com/bobmatnyc/claude-mpm-skills/tree/HEAD/toolchains/typescript/data/prisma/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
