पाठ 19 / 35
Prisma Migrate in Practice
यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।
Use migrate dev, migrate deploy, migrate reset and db push for the right job, and edit a generated migration before applying it.
लेखक: Rahul Agarwal · 15 साल से वेब डेवलपर
Development commands vs deployment commands
Prisma Migrate compares your schema.prisma with the migration history and generates SQL. prisma migrate dev is for development: it creates a new folder under prisma/migrations/ containing migration.sql, applies it to your development database, and can detect drift when the database no longer matches the history, in which case it may offer to reset the database. prisma migrate deploy is for staging and production: it applies pending migrations and never generates new ones or resets anything, which makes it safe for CI pipelines. prisma migrate reset drops and recreates the development database, then reapplies all migrations. prisma db push pushes the schema straight to the database without creating migration files, which is handy while prototyping but leaves no history. When Prisma cannot tell a rename from a drop-and-add, it generates the destructive version, so use --create-only to generate the file, edit the SQL, then apply it.
A typical day with Prisma Migrate
Commands only; each one reads schema.prisma and the connection URL from your configuration.
# after editing schema.prisma in development
npx prisma migrate dev --name add-user-bio
# need to edit SQL first (for example a rename)?
npx prisma migrate dev --name rename-handle --create-only
# ...edit prisma/migrations/<timestamp>_rename-handle/migration.sql...
npx prisma migrate dev
# regenerate the client if your version does not do it automatically
npx prisma generate
# in CI or production
npx prisma migrate deployNever run migrate dev against production
migrate dev is interactive and may propose resetting the database when it detects drift. Production pipelines should only ever run migrate deploy, using a database user that has the rights to alter tables.
त्वरित जाँच: Which Prisma command belongs in a production deployment pipeline?
- prisma migrate dev
- prisma migrate deploy
- prisma migrate reset
- prisma db push --force-reset
Answer
prisma migrate deploy — migrate deploy applies already-committed migrations and nothing else. The other commands can create migrations, reset data or bypass migration history.