Skip to content

skillDatabasestypescriptprisma

Prisma Schema Workflow

Evolves a Prisma schema safely with named migrations, seed scripts, type-safe queries and a check for destructive changes.

npx workspacetemplates add prisma-schema-workflow --tool claude-code

Writes 1 file to .claude/skills/prisma-schema-workflow/

.claude/skills/prisma-schema-workflow/SKILL.md28 lines · 1.7 KBFile
---
name: prisma-schema-workflow
description: Evolves a Prisma schema safely with named migrations, seed scripts, type-safe queries and a check for destructive changes.
---

# Prisma schema workflow

Treat `schema.prisma` and the migration SQL as reviewed code.

## Steps

1. Read `schema.prisma`, the latest migrations and `package.json` scripts. Confirm which database and whether migrations are used (`prisma migrate`) or push (`db push`). Do not mix them on one database.
2. Edit the schema: explicit `@id`, `@unique`, `@@index` for each foreign key and filter, relation names when a model has two relations to another, and `onDelete` behavior stated rather than default.
3. Generate the migration with `npx prisma migrate dev --name add_invoice_status` using a descriptive name. Use `--create-only` when the change needs hand edits.
4. Open the generated `migration.sql` and read it. Stop and ask before any `DROP`, a type change, or a new required column on a populated table. For the latter, add it optional, backfill, then make it required in a later migration.
5. Run `npx prisma generate` and fix type errors; they are the list of code to update.
6. Write queries with `select` or `include` for only what the caller needs. Use `$transaction` for related writes, and `createMany` for bulk inserts.
7. Keep `prisma/seed.ts` idempotent with `upsert`, and run it with `prisma db seed`.
8. In CI and production use `prisma migrate deploy`, never `migrate dev`.

## Rules

- Never edit a migration that has already been applied elsewhere; add a new one.
- On drift, run `migrate diff` to see it before any reset, and never reset a shared database.

## Report

The schema diff, the migration SQL highlights, code changes and how you verified them.

What it does

Prisma makes schema changes easy to write and easy to get wrong. This skill gives the agent a repeatable loop: edit the schema, generate a named migration, read the SQL it produced, then update code and seeds.

The step most people skip is reading the generated SQL, which is where dropped columns and table rewrites show up.

Example

you › Add invoice status and a paidAt date to our Prisma schema

agent › Added enum InvoiceStatus and paidAt DateTime?. The migration SQL created the enum and an optional column, no table rewrite. Updated 4 query sites flagged by tsc, made the seed idempotent with upsert, and added an index on (customerId, status).

Questions

migrate dev or db push?
Use migrate dev when you want a history you can review and deploy. db push suits throwaway prototypes only, since it leaves no migration files.
How do I rename a field without losing data?
Use `@map` to keep the column name, or edit the generated SQL to a RENAME statement with --create-only. Plain rename in the schema otherwise generates a drop and add.
  • Database Connection Pooling

    SkillDatabases

    Free
  • Database Migration Safety

    SkillDatabases

    Free
  • Database Schema Design

    SkillDatabases

    Free
  • MongoDB Schema Modeling

    Skillmongodb

    Free