BACK TO DIRECTORY
commandintermediate

/migrate

Manages database schema migrations for Prisma, Drizzle, or raw SQL projects. Can generate new migrations from schema changes, run pending migrations, rollback the last migration, check migration status, and seed the database. Includes safety checks for production environments and generates migration names from the schema diff.

389 STARS
5.1k DOWNLOADS
claude-templates
databasemigrationsprismadrizzleschema

CONFIGURATION

markdown
1# /migrate Command
2
3## Description
4Manage database schema migrations.
5
6## Commands
7
8### Generate Migration
9Create a new migration from schema changes:
10```bash
11# Prisma
12npx prisma migrate dev --name add_user_roles
13
14# Drizzle
15npx drizzle-kit generate --name add_user_roles
16```
17
18### Run Migrations
19Apply pending migrations:
20```bash
21# Development
22npx prisma migrate dev
23
24# Production
25npx prisma migrate deploy
26```
27
28### Check Status
29View migration history:
30```bash
31npx prisma migrate status
32```
33
34### Reset Database
35Reset and re-run all migrations (DEVELOPMENT ONLY):
36```bash
37npx prisma migrate reset --force
38```
39
40### Seed Database
41Populate with test data:
42```bash
43npx prisma db seed
44```
45
46## Safety Checks
47Before running migrations in production:
481. Verify backup exists
492. Check for destructive changes (DROP TABLE, DROP COLUMN)
503. Estimate migration duration for large tables
514. Plan for zero-downtime (add column, then backfill, then add constraint)
52
53## Best Practices
54- Never edit a migration after it has been applied
55- One logical change per migration
56- Test migrations on a copy of production data
57- Include both up and down migrations
58- Name migrations descriptively (add_user_email_index)
59
60## Usage
61- `/migrate` - Run pending migrations
62- `/migrate new` - Generate new migration
63- `/migrate status` - Check migration state
64- `/migrate reset` - Reset database (dev only)