Use --create-only when you need to review or edit the SQL:
1
Create Draft Migration
prisma migrate dev --create-only --name add_custom_index
Output:
Prisma Migrate created the following migration without applying it 20201231000000_add_custom_indexYou can now edit it and apply it by running prisma migrate dev.
-- CreateIndexCREATE INDEX "User_email_name_idx" ON "User"("email", "name");-- Custom: Add partial index for active usersCREATE INDEX "User_active_email_idx" ON "User"("email") WHERE "deletedAt" IS NULL;
3
Apply the Migration
prisma migrate dev
The edited migration will be applied to your database.
Sometimes Prisma Migrate needs to reset your database:
Drift detected: Your database schema is not in sync with your migration history.We need to reset the "public" schemaYou may use prisma migrate reset to drop the development database.All data will be lost.
2 migrations found in prisma/migrationsFollowing migration has not yet been applied:20210101120000_add_analyticsTo apply migrations in production run prisma migrate deploy.
4
Deploy Migrations
Apply pending migrations:
prisma migrate deploy
Output:
1 migration found in prisma/migrationsThe following migration(s) have been applied:migrations/ └─ 20210101120000_add_analytics/ └─ migration.sqlAll migrations have been successfully applied.
3 migrations found in prisma/migrationsFollowing migration has not yet been applied:20210115120000_add_notificationsTo apply migrations in development run prisma migrate dev.To apply migrations in production run prisma migrate deploy.
Following migration has failed:20210115120000_add_notificationsDuring development if the failed migration has not been deployed to a production database you can then fix the migration and run prisma migrate dev.The failed migration can be marked as rolled back or applied:- If you rolled back the migration manually:prisma migrate resolve --rolled-back "20210115120000_add_notifications"- If you fixed the database manually (hotfix):prisma migrate resolve --applied "20210115120000_add_notifications"