Migrations
An overview of the database setup and management using Prisma.
Production
Zero Manual Intervention
Migrations are executed automatically during the deployment startup phase. You do not need to run any manual database migration commands on your server after deploying.
In production environments, the application automatically triggers the npx prisma migrate deploy command before the main application process starts. This seamlessly guarantees that your database schema remains in sync with your newly deployed code.
Local development
Use these commands while developing locally. Here is the typical sequence of commands when modifying your database schema.
1. Format Prisma schema
After making changes to your schema.prisma file, format the file before creating a migration:
npx prisma format2. Create and apply a new migration
Create a new migration and apply it to your local database. This command will also automatically regenerate the Prisma Client.
npx prisma migrate devOther useful commands
Generate Prisma Client manually: Useful if you pulled changes from your repository that don't require new migrations and just need to update the generated types.
npx prisma generateApply existing migrations: Applies migrations without creating new ones (acting the same way a production deploy does).
npx prisma migrate deployReset local database: Drops the database, applies all migrations from scratch, and automatically runs the seed script.
npx prisma migrate resetSeed database manually:
pnpm db:seed