git clone https://github.com/Intense-Visions/harness-engineering
T=$(mktemp -d) && git clone --depth=1 https://github.com/Intense-Visions/harness-engineering "$T" && mkdir -p ~/.claude/skills && cp -r "$T/agents/skills/claude-code/prisma-migrations" ~/.claude/skills/intense-visions-harness-engineering-prisma-migrations && rm -rf "$T"
agents/skills/claude-code/prisma-migrations/SKILL.mdPrisma Migrations
Manage database schema evolution with prisma migrate dev/deploy/reset and migration history
When to Use
- Applying schema changes to the database during development
- Deploying migrations to staging or production environments
- Baselining an existing database for Prisma Migrate adoption
- Resolving migration history conflicts or drift
Instructions
- Development workflow — after editing
, run:schema.prisma
npx prisma migrate dev --name describe_the_change
This generates a migration SQL file, applies it, and regenerates Prisma Client.
- Production deployment — never use
in production. Use:migrate dev
npx prisma migrate deploy
This applies all pending migrations without generating new ones.
- Reset the database (development only) — drops the database, recreates it, applies all migrations, and runs the seed script:
npx prisma migrate reset
- Baseline an existing database — when adopting Prisma Migrate on a database that already has tables:
mkdir -p prisma/migrations/0_init npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql npx prisma migrate resolve --applied 0_init
- Check for drift between the schema and the database:
npx prisma migrate diff --from-schema-datamodel prisma/schema.prisma --to-schema-datasource prisma/schema.prisma
-
Customize generated SQL — after
creates a migration file, edit it before committing. Prisma will not overwrite your edits on subsequent runs.migrate dev -
Handle failed migrations — if a migration partially applied:
# Fix the database state manually, then mark as applied: npx prisma migrate resolve --applied MIGRATION_NAME # Or mark as rolled back: npx prisma migrate resolve --rolled-back MIGRATION_NAME
- Shadow database —
requires a shadow database to detect drift. Configure it explicitly if your provider does not allow automatic creation:migrate dev
datasource db { provider = "postgresql" url = env("DATABASE_URL") shadowDatabaseUrl = env("SHADOW_DATABASE_URL") }
-
Always commit migration files (
) to version control. They are the source of truth for production.prisma/migrations/ -
Never delete or reorder migration directories once they have been applied to any environment.
Details
Prisma Migrate uses a migrations table (
_prisma_migrations) to track which migrations have been applied. Each migration is a directory containing a migration.sql file and is applied in lexicographic order.
Migration history vs schema state: The migration history is the authoritative record. The schema file describes the desired end state. If these diverge (drift),
migrate dev will detect it via the shadow database.
Shadow database mechanics: During
migrate dev, Prisma creates a temporary shadow database, applies all existing migrations to it, computes the diff against your schema, and generates the new migration. The shadow database is dropped afterward. This means you need CREATE DATABASE privileges in development.
Data migrations: Prisma generates only DDL (schema changes). If you need DML (data changes — backfills, column value transforms), add raw SQL to the generated migration file before committing.
Trade-offs:
is safe and reversible (viamigrate dev
), but slow on large schemas due to shadow database overheadreset
is fast but irreversible — there is no built-in rollback. Write reverse migrations manually if neededmigrate deploy
skips migration history entirely — use it only for rapid prototyping, never in a shared environmentdb push
Common mistakes:
- Running
in CI — it generates files and requires a shadow database. Usemigrate dev
insteadmigrate deploy - Deleting migration files to "clean up" — this breaks the migration history for any database that already applied them
- Not testing migrations on a copy of production data before deploying — column type changes or NOT NULL additions can fail on existing data
Source
https://prisma.io/docs/orm/prisma-migrate
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.