|
| 1 | +--- |
| 2 | +name: prisma-cli |
| 3 | +description: Prisma ORM CLI commands reference covering init, generate, migrate, db, dev, studio, validate, format, debug, and mcp. Use for ORM/database CLI workflows, not Prisma Compute app deployment. For Prisma Compute, `@prisma/cli app deploy`, `compute:deploy`, `create-prisma --deploy`, apps, deployments, logs, or domains, use the `prisma-compute` skill instead. Triggers on "prisma init", "prisma generate", "prisma migrate", "prisma db", "prisma studio", "prisma mcp". |
| 4 | +license: MIT |
| 5 | +metadata: |
| 6 | + author: prisma |
| 7 | + version: "7.6.0" |
| 8 | +--- |
| 9 | + |
| 10 | +# Prisma CLI Reference |
| 11 | + |
| 12 | +Reference for Prisma ORM CLI commands. This skill provides guidance on command usage, options, and best practices for current Prisma ORM releases. |
| 13 | + |
| 14 | +## Boundary: Compute |
| 15 | + |
| 16 | +Do not use this skill for Prisma Compute app deployment. Use `prisma-compute` for `@prisma/cli app deploy`, `compute:deploy`, `create-prisma --deploy`, Compute apps, deployments, logs, domains, and framework deploy readiness. |
| 17 | + |
| 18 | +## When to Apply |
| 19 | + |
| 20 | +Reference this skill when: |
| 21 | +- Setting up a new Prisma project (`prisma init`) |
| 22 | +- Generating Prisma Client (`prisma generate`) |
| 23 | +- Running database migrations (`prisma migrate`) |
| 24 | +- Managing database state (`prisma db push/pull`) |
| 25 | +- Using local development database (`prisma dev`) |
| 26 | +- Debugging Prisma issues (`prisma debug`) |
| 27 | + |
| 28 | +## Rule Categories by Priority |
| 29 | + |
| 30 | +| Priority | Category | Impact | Prefix | |
| 31 | +|----------|----------|--------|--------| |
| 32 | +| 1 | Setup | HIGH | `init` | |
| 33 | +| 2 | Generation | HIGH | `generate` | |
| 34 | +| 3 | Development | HIGH | `dev` | |
| 35 | +| 4 | Database | HIGH | `db-` | |
| 36 | +| 5 | Migrations | CRITICAL | `migrate-` | |
| 37 | +| 6 | Utility | MEDIUM | `studio`, `validate`, `format`, `debug`, `mcp` | |
| 38 | + |
| 39 | +## Command Categories |
| 40 | + |
| 41 | +| Category | Commands | Purpose | |
| 42 | +|----------|----------|---------| |
| 43 | +| Setup | `init` | Bootstrap new Prisma project | |
| 44 | +| Generation | `generate` | Generate Prisma Client | |
| 45 | +| Validation | `validate`, `format` | Schema validation and formatting | |
| 46 | +| Development | `dev` | Local Prisma Postgres for development | |
| 47 | +| Database | `db pull`, `db push`, `db seed`, `db execute` | Direct database operations | |
| 48 | +| Migrations | `migrate dev`, `migrate deploy`, `migrate reset`, `migrate status`, `migrate diff`, `migrate resolve` | Schema migrations | |
| 49 | +| Utility | `studio`, `mcp`, `version`, `debug` | Development and AI tooling | |
| 50 | + |
| 51 | +## Quick Reference |
| 52 | + |
| 53 | +### Project Setup |
| 54 | + |
| 55 | +```bash |
| 56 | +# Initialize new project (creates prisma/ folder and prisma.config.ts) |
| 57 | +prisma init |
| 58 | + |
| 59 | +# Initialize with specific database |
| 60 | +prisma init --datasource-provider postgresql |
| 61 | +prisma init --datasource-provider mysql |
| 62 | +prisma init --datasource-provider sqlite |
| 63 | + |
| 64 | +# Initialize with Prisma Postgres (cloud) |
| 65 | +prisma init --db |
| 66 | + |
| 67 | +# Initialize with an example model |
| 68 | +prisma init --with-model |
| 69 | +``` |
| 70 | + |
| 71 | +### Client Generation |
| 72 | + |
| 73 | +```bash |
| 74 | +# Generate Prisma Client |
| 75 | +prisma generate |
| 76 | + |
| 77 | +# Watch mode for development |
| 78 | +prisma generate --watch |
| 79 | + |
| 80 | +# Generate specific generator only |
| 81 | +prisma generate --generator client |
| 82 | +``` |
| 83 | + |
| 84 | +### Bun Runtime |
| 85 | + |
| 86 | +When using Bun, always add the `--bun` flag so Prisma runs with the Bun runtime (otherwise it falls back to Node.js because of the CLI shebang): |
| 87 | + |
| 88 | +```bash |
| 89 | +bunx --bun prisma init |
| 90 | +bunx --bun prisma generate |
| 91 | +``` |
| 92 | + |
| 93 | +### Local Development Database |
| 94 | + |
| 95 | +```bash |
| 96 | +# Start local Prisma Postgres |
| 97 | +prisma dev |
| 98 | + |
| 99 | +# Start with specific name |
| 100 | +prisma dev --name myproject |
| 101 | + |
| 102 | +# Start in background (detached) |
| 103 | +prisma dev --detach |
| 104 | + |
| 105 | +# List all local instances |
| 106 | +prisma dev ls |
| 107 | + |
| 108 | +# Stop instance |
| 109 | +prisma dev stop myproject |
| 110 | + |
| 111 | +# Remove instance data |
| 112 | +prisma dev rm myproject |
| 113 | +``` |
| 114 | + |
| 115 | +### Database Operations |
| 116 | + |
| 117 | +```bash |
| 118 | +# Pull schema from existing database |
| 119 | +prisma db pull |
| 120 | + |
| 121 | +# Push schema to database (no migrations) |
| 122 | +prisma db push |
| 123 | + |
| 124 | +# Seed database |
| 125 | +prisma db seed |
| 126 | + |
| 127 | +# Execute raw SQL |
| 128 | +prisma db execute --file ./script.sql |
| 129 | +``` |
| 130 | + |
| 131 | +### Migrations (Development) |
| 132 | + |
| 133 | +```bash |
| 134 | +# Create and apply migration |
| 135 | +prisma migrate dev |
| 136 | + |
| 137 | +# Create migration with name |
| 138 | +prisma migrate dev --name add_users_table |
| 139 | + |
| 140 | +# Create migration without applying |
| 141 | +prisma migrate dev --create-only |
| 142 | + |
| 143 | +# Reset database and apply all migrations |
| 144 | +prisma migrate reset |
| 145 | +``` |
| 146 | + |
| 147 | +### Migrations (Production) |
| 148 | + |
| 149 | +```bash |
| 150 | +# Apply pending migrations (CI/CD) |
| 151 | +prisma migrate deploy |
| 152 | + |
| 153 | +# Check migration status |
| 154 | +prisma migrate status |
| 155 | + |
| 156 | +# Compare schemas and generate diff |
| 157 | +prisma migrate diff --from-config-datasource --to-schema schema.prisma --script |
| 158 | +``` |
| 159 | + |
| 160 | +### Utility Commands |
| 161 | + |
| 162 | +```bash |
| 163 | +# Open Prisma Studio (database GUI) |
| 164 | +prisma studio |
| 165 | + |
| 166 | +# Start Prisma's MCP server for AI tools |
| 167 | +prisma mcp |
| 168 | + |
| 169 | +# Show version info |
| 170 | +prisma version |
| 171 | +prisma -v |
| 172 | + |
| 173 | +# Debug information |
| 174 | +prisma debug |
| 175 | + |
| 176 | +# Validate schema |
| 177 | +prisma validate |
| 178 | + |
| 179 | +# Format schema |
| 180 | +prisma format |
| 181 | +``` |
| 182 | + |
| 183 | +## Current Prisma CLI Setup |
| 184 | + |
| 185 | +### New Configuration File |
| 186 | + |
| 187 | +Use `prisma.config.ts` for CLI configuration: |
| 188 | + |
| 189 | +```typescript |
| 190 | +import 'dotenv/config' |
| 191 | +import { defineConfig, env } from 'prisma/config' |
| 192 | + |
| 193 | +export default defineConfig({ |
| 194 | + schema: 'prisma/schema.prisma', |
| 195 | + migrations: { |
| 196 | + path: 'prisma/migrations', |
| 197 | + seed: 'tsx prisma/seed.ts', |
| 198 | + }, |
| 199 | + datasource: { |
| 200 | + url: env('DATABASE_URL'), |
| 201 | + }, |
| 202 | +}) |
| 203 | +``` |
| 204 | + |
| 205 | +### Current Command Behavior |
| 206 | + |
| 207 | +- Run `prisma generate` explicitly after `migrate dev`, `db push`, or other schema syncs when you need fresh client output |
| 208 | +- Run `prisma db seed` explicitly after `migrate dev` or `migrate reset` when you need seed data |
| 209 | +- Use `prisma db execute --file ...` for raw SQL scripts |
| 210 | + |
| 211 | +### Environment Variables |
| 212 | + |
| 213 | +Load environment variables explicitly in `prisma.config.ts`, commonly with `dotenv`: |
| 214 | + |
| 215 | +```typescript |
| 216 | +// prisma.config.ts |
| 217 | +import 'dotenv/config' |
| 218 | +``` |
| 219 | + |
| 220 | +## Rule Files |
| 221 | + |
| 222 | +See individual rule files for detailed command documentation: |
| 223 | + |
| 224 | +``` |
| 225 | +references/init.md - Project initialization |
| 226 | +references/generate.md - Client generation |
| 227 | +references/dev.md - Local development database |
| 228 | +references/db-pull.md - Database introspection |
| 229 | +references/db-push.md - Schema push |
| 230 | +references/db-seed.md - Database seeding |
| 231 | +references/db-execute.md - Raw SQL execution |
| 232 | +references/migrate-dev.md - Development migrations |
| 233 | +references/migrate-deploy.md - Production migrations |
| 234 | +references/migrate-reset.md - Database reset |
| 235 | +references/migrate-status.md - Migration status |
| 236 | +references/migrate-resolve.md - Migration resolution |
| 237 | +references/migrate-diff.md - Schema diffing |
| 238 | +references/studio.md - Database GUI |
| 239 | +references/mcp.md - Prisma MCP server |
| 240 | +references/validate.md - Schema validation |
| 241 | +references/format.md - Schema formatting |
| 242 | +references/debug.md - Debug info |
| 243 | +``` |
| 244 | + |
| 245 | +## How to Use |
| 246 | + |
| 247 | +Use the command categories above for navigation, then open the specific command reference file you need. |
0 commit comments