Universal AI Lib
cd ../skills

Prisma Best Practices

Operate Prisma schema and migration workflows safely: edit models, generate client, choose migration strategy, and debug runtime issues.

# Prisma Best Practices

## When to Use
Apply when working with Prisma ORM in any Node.js/TypeScript project.

## Rules
1. **Always run `prisma generate` after schema changes** — the client must match the schema.
2. **Use `prisma migrate dev` in development**, `prisma migrate deploy` in production.
3. **Never edit migration SQL files** after they have been applied.
4. **Use `@map` and `@@map` decorators** to keep Prisma model names camelCase while using snake_case in the database.
5. **Add indexes** for commonly queried fields with `@@index`.

## Code Examples

```prisma
model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  posts     Post[]
  createdAt DateTime @default(now()) @map("created_at")
  updatedAt DateTime @updatedAt @map("updated_at")

  @@map("users")
}
```

## Anti-Patterns
- Using raw SQL when Prisma Client can do it
- Forgetting to regenerate after schema changes
- Using `db push` in production (use `migrate deploy` instead)

## Checklist
- [ ] Schema changes committed with migration
- [ ] `prisma generate` ran after changes
- [ ] Indexes added for filter/sort fields
- [ ] No raw SQL unless absolutely necessary

How to use this skill

  1. Click "Copy" to copy the skill content.
  2. Create a folder at .github/skills/prisma-best-practices/ in your repository.
  3. Paste the content into SKILL.md inside the folder.
  4. Reference the skill name in your AI agent's instructions or copilot config.