Theo Letouze
09/29/2022, 10:48 AMRaphael Etim
09/29/2022, 2:07 PMnpx prisma migrate dev --name introspected_change
Theo Letouze
09/29/2022, 2:13 PMRaphael Etim
09/29/2022, 2:17 PMTheo Letouze
09/29/2022, 2:20 PMIf Prisma Migrate detects a migration history conflict when you run prisma migrate dev, the CLI will ask to reset the database and reapply the migration history.
But it’s diffucult for me to reset my database because I have a script to seed my db with initial data which take 1 hour to be executedRaphael Etim
09/29/2022, 2:24 PMTheo Letouze
09/29/2022, 2:30 PMRaphael Etim
09/29/2022, 2:49 PMTheo Letouze
09/29/2022, 2:52 PMRaphael Etim
09/29/2022, 4:21 PMprisma migrate diff
can be of help here since you can migrate diff
your migration history directory with the current database schema to know what further changes are necessary to bring your database schema to your desired state.prisma migrate diff
work for you?Theo Letouze
09/30/2022, 7:38 AMprisma migrate diff
can update my migrations folder but not my prisma schema right?Raphael Etim
09/30/2022, 10:06 AMTheo Letouze
09/30/2022, 10:19 AMVladi Stevanovic
Theo Letouze
10/03/2022, 10:09 AMRaphael Etim
10/04/2022, 7:05 AMTheo Letouze
10/04/2022, 9:56 AMRaphael Etim
10/04/2022, 2:15 PMTheo Letouze
10/04/2022, 4:43 PMRaphael Etim
10/04/2022, 5:21 PMprisma db execute
command.Theo Letouze
10/04/2022, 5:24 PMAlex Ruheni
But imagine I’m on a branch “b” and a colleague is on a branch “a”, my colleague does a migration (on branch “a”) to add a field to the user’s table. Few minutes after I want to create a new migration on my branch (branch “b”). I’ll have an error because the migration table in the database has a new line with my colleague’s migration which is not in my migration folder. So I can’t make a new migrationBased on this, I have a follow-up question: • Are you sharing the same database between both branches? Generally, I recommend using a separate table when working in different environments, i.e., staging, prod, and locally. If you’re working with PostgreSQL and Netlify/ Vercel, Snaplet is working on a Preview Database plugin. This could serve as inspiration when isolating databases in different environments. One way to think about Prisma Migrate regarding schema drifts is that it’s a state management tool for database schemas. (If you’re sharing the same database): In the scenario you shared, if I understand correctly, your colleague updated the database by adding a field, your “branch.” In this case, your Prisma schema and database migrations are one step behind your colleagues. Your colleague’s migration was already marked as applied by Prisma Migrate when they made the change. To fix this, you could merge your colleague’s branch into yours. This would update your version of the Prisma schema and migration history—
/prisma/migrations
. You could then confirm it’s resolved by running prisma migrate deploy
.
(If you’re working on separate branches and separate databases) You can resolve the conflict by merging your colleague’s branch into yours — it would contain the updated Prisma schema migration history. You can then run prisma migrate deploy
or prisma migrate dev
to apply any pending changes to your development database.
You will then be able to continue making schema changes to your database after this. Let me know if this answers your question @Theo Letouze. 🙂Theo Letouze
10/12/2022, 10:10 AMAlex Ruheni
./prisma/migrations
directory from your co-worker’s branch might be a more elegant solution for your case. The migration workflow might be a little more complex, but that should do it.
Follow-up question, if you don’t mind, is there a particular reason you’re sharing the development database? I’d like to learn more about your use case 🙂Theo Letouze
10/12/2022, 10:34 AM