Skip to main content
ClaudeWave
Skill58 estrellas del repoactualizado 2mo ago

prisma-database

Prisma ORM schema design, migrations, client generation, and query patterns. Use when designing database schemas, writing migrations, querying data, or managing Prisma Client.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/monkilabs/opencastle /tmp/prisma-database && cp -r /tmp/prisma-database/src/orchestrator/plugins/prisma ~/.claude/skills/prisma-database
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

<!-- ⚠️ This file is managed by OpenCastle. Edits will be overwritten on update. Customize in the .opencastle/ directory instead. -->

# Prisma Database

For project-specific database schema and connection details, see [database-config.md](../../.opencastle/stack/database-config.md).

## Commands

```bash
npx prisma init                    # Initialize Prisma in the project
npx prisma generate                # Generate Prisma Client from schema
npx prisma migrate dev             # Create and apply migration (dev)
npx prisma migrate deploy          # Apply pending migrations (production)
npx prisma migrate reset           # Reset database and apply all migrations
npx prisma db push                 # Push schema changes without migration
npx prisma db pull                 # Introspect database into schema
npx prisma db seed                 # Run seed script
npx prisma studio                  # Open visual database editor
npx prisma format                  # Format schema file
npx prisma validate                # Validate schema syntax
```

## Schema Design

```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

  @@index([email])
  @@map("users")
}

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

  @@index([authorId])
  @@map("posts")
}
```

### Schema Best Practices (Prisma gotchas)

- Use `cuid()` or `uuid()` for IDs in distributed systems (avoid serial increments).
- Always include `createdAt` and `updatedAt` timestamps for auditability and migrations.
- Prefer explicit `@relation` definitions and add `@@index` on frequently queried columns.
- Review `@map`/`@@map` uses when renaming to prevent accidental column/table mismatches.
- Avoid editing applied migration files; create corrective migrations instead.

## Migration Rules (Prisma-specific)

1. Use `npx prisma migrate dev` during development to generate migrations; inspect the generated SQL before applying.
2. Use `npx prisma migrate deploy` in CI/CD; never run `migrate dev` in production.
3. Name migrations descriptively and include backfill steps for destructive changes.
4. Regenerate the client after schema changes: `npx prisma generate`.

## Migration Workflow: validate → fix → retry (Prisma-focused)
1. Run `npx prisma migrate dev --name <desc>` locally to generate SQL.
2. Inspect `prisma/migrations/<timestamp>/migration.sql` for destructive operations and add backfills as needed.
3. Apply to a local/ephemeral DB and run tests; revert and adjust if failures occur.
4. Push migration to CI with `npx prisma migrate deploy` and assert clean application.

For query patterns, singleton client pattern, and runnable CRUD examples see REFERENCE.md in this directory.
astro-frameworkSkill

Creates pages/layouts, defines content collections, configures hydration directives, and wires integrations. Use when adding or modifying Astro pages, layouts, components, or content collections. Trigger terms: Astro, content collection, client:load, client:visible, astro:content

browser-testingSkill

Drive real browsers via Chrome DevTools MCP: navigate pages, capture snapshots, run responsive checks, and collect console/perf traces. Use when the user mentions: 'validate UI change in Chrome', 'capture a screenshot', 'run responsive checks', or 'collect console logs'. Trigger terms: browser testing, DevTools, console logs, screenshot, responsive testing

cloudflare-platformSkill

Creates and deploys Cloudflare Workers, configures wrangler.toml bindings, sets up KV/D1/R2 storage and Durable Objects, manages Pages deployments, and implements edge function patterns. Use when building or deploying Cloudflare Workers, setting up Pages, working with KV/D1/R2 storage, configuring wrangler.toml, or deploying edge applications.

contentful-cmsSkill

Creates Contentful content types, queries entries via GraphQL/REST, runs CLI migrations, and manages assets and locales. Use when building or modifying Contentful content models, writing queries, or migrating content.

convex-databaseSkill

Convex reactive database patterns, schema design, real-time queries, mutations, actions, authentication, migrations, performance optimization, and component creation. Use when designing Convex schemas, writing queries/mutations, managing the Convex backend, setting up auth, migrating data, optimizing performance, or building Convex components.

coolify-deploymentSkill

Deploys applications, databases, and services on self-hosted Coolify instances, manages environments and env vars, runs infrastructure diagnostics, and performs batch operations. Use when deploying apps to Coolify, managing Coolify servers, debugging deployment issues, setting up databases, or managing Coolify infrastructure.

cypress-testingSkill

Writes Cypress E2E/component tests, configures `cy.intercept()` and `cy.session()`, authors custom commands, and wires CI artifacts. Use when creating E2E specs, component tests, or CI test pipelines. Trigger terms: cypress, e2e, component test, cy.intercept, cy.session

drizzle-ormSkill

Drizzle ORM schema definition, type-safe queries, relational queries, CRUD operations, transactions, migrations with drizzle-kit, and database setup for PostgreSQL, MySQL, and SQLite. Use when defining database schemas, writing queries or joins, managing migrations, setting up a new Drizzle project, or working with drizzle-kit.