I get “drift detected” a LOT in `migrate dev`; if ...
# orm-help
d
I get “drift detected” a LOT in `migrate dev`; if I DON’T want to delete my data what can I do to fix these situations?
f
Migrate dev is designed around resetting the development db to be able to re-play migration files to the db. During active development you could use db push while iterating and then only run migrate dev once when your schema is finished. But that would still require one reset.
d
but if I’ve been using migrate dev to iterate on changes, how can the database and the migrations get out of sync? One database, one user; it should be in sync.
I have 1,168,165 rows of data in the DB; Its not easy to constantly have to re-insert the data.
f
Yeah, we unfortunately know the requirement to reset is not great for users that can't reset/seed their db.
d
Also once I get into production, how can I migrate the data from there?
in production I’ll have the same problem.
f
You should not use migrate dev in production as it's a development command. Use migrate deploy which doesn't detect drift/resets
d
you still havent told me why, if I do migrate dev in a single environment, drift happens? It shouldn’t drift if the database and the migrations are the same
f
Drift means the schema of the database is ahead of the migration files. Are you changing the DB schema outside of prisma somehow?
d
no
thats my point. I am just running migrate dev. no push/pull etc, no hand changes to schema.
Is there a way I can “fix” the drift triggers so it doesnt force me to reload?
m
I think your fix is to run the “baseline” workflow, which is what I’m also trying to do to also fix a drift issue. We DID have a drift issue where one of our devs updated a migration by adding a comment, after it ran. But even though we fixed that, now prisma complains that there are a LOT of changes, but then it generates an empty migration with no change 🤷
With the baseline, your prisma file and database should be in sync, which would stop complaining about drift issues But i’m still having it somehow
d
the “drift” is described as [+] Added tables - cmda_exec thats not a specific migration is it?
f
Hm, could you run migrate diff to compare your db schema with the migration history using the —script param?
d
what exact params should I have?
f
Im on mobile but use diff to get the SQL that would migrate the DB schema to the state of the migration history: https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-diff
And then compare —from-schema-datasource with —to-migrations
Is there any custom SQL in your migration files?
j
What do you know about this table? Is this already managed via the Prisma schema? Was it always there? Was it added recently? If so, how?