They serve two different environments. The prisma db push is not to be used in your production environment, as stated in the docs
db pushuses the same engine as Prisma Migrate to synchronize your Prisma schema with your database schema, and is best suited for schema prototyping. Thedb pushcommand:
Introspects the database to infer and executes the changes required to make your database schema reflect the state of your Prisma schema.
By default, after changes have been applied to the database schema, generators are triggered (for example, Prisma Client). You do not need to manually invoke
prisma generate.If
db pushanticipates that the changes could result in data loss, it will:
- Throw an error
- Require the
--accept-data-lossoption if you still want to make the changesNote:
db pushdoes not interact with or rely on migrations. The migrations table will not be updated, and no migration files will be generated.
The prisma migrate dev is used in you local environment, as explained in the docs
migrate devis a development command and should never be used in a production environment.This command:
- Replays the existing migration history in the shadow database in order to detect schema drift (edited or deleted migration file, or a manual changes to the database schema)
- Applies pending migrations to the shadow database (for example, new migrations created by colleagues)
- Generates a new migration from any changes you made to the Prisma schema before running
migrate dev- Applies all unapplied migrations to the development database and updates the
_prisma_migrationstable- Triggers the generation of artifacts (for example, the Prisma Client)
The
migrate devcommand will prompt you to reset the database in the following scenarios:
- Migration history conflicts caused by modified or missing migrations
- The database schema has drifted away from the end-state of the migration history
If you have any other question regarding this, there is this comparison in the docs explaining when to use one or the other.
Answer from Daniel Olavio Ferreira on Stack OverflowHow do I use Prisma without having to wipe my database all the time?
how to generate a migration file with prisma - Stack Overflow
When should you consider not using "prisma migrate"?
Where do you actually run prisma migrate deploy?
They serve two different environments. The prisma db push is not to be used in your production environment, as stated in the docs
db pushuses the same engine as Prisma Migrate to synchronize your Prisma schema with your database schema, and is best suited for schema prototyping. Thedb pushcommand:
Introspects the database to infer and executes the changes required to make your database schema reflect the state of your Prisma schema.
By default, after changes have been applied to the database schema, generators are triggered (for example, Prisma Client). You do not need to manually invoke
prisma generate.If
db pushanticipates that the changes could result in data loss, it will:
- Throw an error
- Require the
--accept-data-lossoption if you still want to make the changesNote:
db pushdoes not interact with or rely on migrations. The migrations table will not be updated, and no migration files will be generated.
The prisma migrate dev is used in you local environment, as explained in the docs
migrate devis a development command and should never be used in a production environment.This command:
- Replays the existing migration history in the shadow database in order to detect schema drift (edited or deleted migration file, or a manual changes to the database schema)
- Applies pending migrations to the shadow database (for example, new migrations created by colleagues)
- Generates a new migration from any changes you made to the Prisma schema before running
migrate dev- Applies all unapplied migrations to the development database and updates the
_prisma_migrationstable- Triggers the generation of artifacts (for example, the Prisma Client)
The
migrate devcommand will prompt you to reset the database in the following scenarios:
- Migration history conflicts caused by modified or missing migrations
- The database schema has drifted away from the end-state of the migration history
If you have any other question regarding this, there is this comparison in the docs explaining when to use one or the other.
- Prisma db push syncs (and formats) your prisma schema to that of your database schema.
- While prisma migrate dev "command automatically generates SQL migration files (saved in /prisma/migrations) and applies them to the database".
The main difference between both is the generation of the migration files.
I'm using Prisma for a large project I've been working on for the past few months, and I still don't understand the flow of it. At first I was migrating every time I made a change to my schema, and constantly getting the "All data will be lost" prompt. Since then I've learned to use `db push` while developing and then migrate when a feature is finished, but it's still constantly making me reset my database.
Right now I'm using the same db for dev and staging (because I don't want to pay for 2 different ones) but I'd imagine this would still be an issue if I had separate databases. What do I need to do to stop being forced to reset my db? Or, at least, how would I migrate my development db to mirror my production db without it being wiped?
As you can probably tell, this is my first time working with Prisma (or any ORM, in depth) so this might be a stupid question, but I can't find much online besides general tutorials. Any help would be greatly appreciated!
I know this was a while ago but the fix is to first make a change in your schema.prisma file. Add whatever changes you need. Then run the command you are running. It will then notice the changes you made on the file and generate the SQL needed to achieve that change. Hope this helps.
Are you trying to do an empty migration? Try using
prisma migrate dev --create-only
doc
Hey all
My name is Rotem, I'm one of the maintainers of atlasgo.io, a database schema-as-code tool, and the CTO of Ariga, the company maintaining it.
We recently published a guide about how to use Atlas with Prisma, essentially replacing the `prisma migrate` command.
Here's the guide
As far as ORMs go u/prisma probably has one of the best schema migration tools out there (`prisma migrate`).
It can automatically plan migrations for you, uses a shadow db to verify them, and has lots of utility subcommands to streamline development.
If you use Prisma, you should probably keep using it.
But there are some cases where you should consider looking at a specialized schema management tool.
Why?
ORMs typically ship with schema management tools.
Without a way to provision the DB schema, the ORM cannot operate, and so any ORM that wants users to have a half-decent experience needs to ship something.
ORMs exist to *abstract* the DB away and give a more or less equivalent experience across databases (e.g should work ~the same for PostgreSQL/MySQL/SQL Server/etc.
As an abstraction layer, they tend to focus on the common DB features (tables, indexes, FKs..)
Being an ORM maintainer myself (entgo.io), I can attest that as an ORM author, migrations are experienced as a "necessary evil", something I have to ship, but really is just an annoying requirement. ORMs exist to bridge code and DB - they are a runtime effort, not a CI/CD or resource management show.
--
So when should you consider using a specialized schema management tool like atlasgo.io?
-
When you want to utilize more advanced features of your DB (view, stored procs, functions, mat views, RLS, ..) and want the same automatic planning experience for those resources.
-
If you're a Platform Eng, and need to support a wide range of languages/frameworks in a standard way. Atlas has adapters/providers that read the schema from the ORM and provide a unified experience
-
If you're a DevOps/Software Delivery focused eng, and want robust CI/CD machinery (k8s operator, terraform provider, github action, gitlab component, etc) and don't want to build all this stuff on your own.
--
TL;DR `prisma migrate` is awesome. You should probably keep using it, but if you relate to the use cases above, we would love for you to try our tool!
If you're interested, here's the link to the guide again:
https://atlasgo.io/guides/orms/prisma
Looking forward to your feedback!
-R
» npm install @prisma/migrate
I'm working on a little project with supabase and prisma, I've just been using one dev database which I update with prisma migrate dev. For production migrations, you're supposed to use prisma migrate deploy, which the prisma docs say to put in a CI/CD pipeline.
-
I don't have a CI/CD pipeline
-
I can't run it locally from my project directory, cause prisma uses the
DATABASE_URLenvironment, which is pointing to my dev database
So I'm wondering where y'all would actually run prisma migrate deploy from? Should I just bite the bullet and learn some github actions? Or is there an easier way?
EDIT: The prisma docs recommend using dotenv-cli to use switch between .env files, but I'm kinda worried that I might fuck up somehow and end up running prisma migrate reset on my prod database, and delete everything. But, seems like that might be my plan until I figure out some CI/CD stuff.
Still definitely open to any advice though!