We migrated several of our huge existing platforms...
# orm-help
j
We migrated several of our huge existing platforms from TypeORM to Prisma in production.
After creating the baseline migration, it is extremely crucial that you mark it as already applied via that
prisma migrate resolve --applied <init migration name>
that creates the entry in the migrations table without actually doing any changes to your schema
then all subsequent migrations are applied
"Baselining tells Prisma Migrate to assume that one or more migrations have already been applied."
Works perfectly.
🤞 1
And of course you have to generate that initial migration from your existing prod DB otherwise you will hose it
Which is why step 1 is "Switch to an environment that has access to the database you want to baseline."
ie production
l
Thanks, @Jacob Martin. My dev database seems properly synched (although empty now). Will give staging a try now.
🙌 1
j
No problem, good luck!
n
Thanks Jacob for chiming in and helping out! 👏
l
So ... is there an assumption that my databases in different environments are 100% in sync? Because they're not 😞
So it seems like the idea is that I'll create the schema from prod, create migrations in other environments, and then tell Prisma that those migrations don't need to be run in prod -- because the schema was made from prod, so it should match. But when I generate a schema from a local copy of my prod database, and then run
prisma migrate dev --name initial-migration --create-only
, it says it has detected drift. I didn't manually change anything in the schema except an enum that was causing errors.
I did successfully run migrations on my local copy of prod without data loss by running a deploy command. Still, I wish Prisma gave me more confidence that prod is in sync with the schema made from prod moments before