티스토리 뷰

RDBMS/Prisma

migrate dev VS db push

James Wetzel 2025. 5. 21. 16:08

The main differences between the prisma migrate dev and prisma db push commands are:

1. Purpose and Workflow

  • migrate dev is designed for development environments and is used to create, apply, and track migrations. It generates SQL migration files based on changes in your Prisma schema, applies them to your database, and updates the migration history. This command helps you maintain a record of all schema changes, which can be shared and applied in other environments (like production or CI/CD) Prisma Migrate CLI reference, How does Prisma Migrate work?.
  • db push is intended for rapid prototyping and development. It directly synchronizes your database schema with your Prisma schema without creating migration files or updating migration history. This is useful for quickly iterating on your schema locally, but it does not provide a record of changes or support deploying those changes to other environments Prototyping your schema.

2. Migration Files and History

  • migrate dev creates and applies migration files, which are stored in your project and can be version-controlled.
  • db push does not create migration files or update the migrations table; it simply updates the database to match the current Prisma schema.

3. Data Loss and Safety

  • migrate dev can prompt you to reset your database if it detects schema drift (differences between the migration history and the actual database schema), which results in data loss in the development database. This is safe in development but should not be used in production Prisma Migrate CLI reference.
  • db push will throw an error or require the --accept-data-loss flag if it anticipates changes that could result in data loss Prototyping your schema.

4. Use in Production

  • migrate dev is for development only. In production, you should use prisma migrate deploy to apply migrations.
  • db push is not recommended for production, except in specific cases like with PlanetScale or MongoDB.

Summary Table:

Feature migrate dev db push
Migration files Yes No
Migration history Yes No
Data loss risk Prompts for reset Requires --accept-data-loss
Production use No No (except special cases)
Use case Development, versioning Rapid prototyping

For more details, see the official documentation: Prototyping your schema, Prisma Migrate CLI reference.

728x90
반응형