Production Migrations after Dev Migrations
Hello, I push my project to a GitHub repo, and I did an initial migration from my dev database and then did migrations after that. I had already hosted my app on Vercel though.
My question, is how can I go about creating an initial migration for my production code if I already pushed my dev migrations to the GitHub repository that is then sent to Vercel?
I think my dev migrations are in the repo the prod is using, so when I run the init prisma migration, the code throws an error.
Do I need to have a production branch and dev branch? Where the prod has the migrations for prod? And if so how would I best go about setting that up if I already pushed my old migrations?
I already have separate DB’s for each case
13 Replies
If I understand correctly, you want to apply migrations already applied on your development database to your production database, right?
Did you check this guide?
https://www.prisma.io/docs/orm/prisma-migrate/workflows/squashing-migrations#how-to-migrate-cleanly-from-a-development-environment
Squashing migrations | Prisma Documentation
How to squash multiple migration files into a single migration
Correct, I think I missed that guide but after reading it I had a question about this part:
"1. Reset the contents of your local
./prisma/migrations
..."
By reset, does that mean delete all my migrations in the migrations folder?It means that the migrations on your GitHub main branch and your local migrations should look same.
When I run the command, it doesn't end up producing the
migration.sql
file, or the squashed_migrations
directory
This is what I get back:
Any ideas on what I could be missing?
Thanks for your time btwThis is what I get in vercel when I try to migrate deploy, thought that might help
Just noticed I forgot to reply, doing it now in case that’s how you keep track of the questions
Does your migration history locally and the one in GitHub main branch exactly same?
Can you try running this migrate diff command to see the difference between your database and the local migrations
https://www.prisma.io/docs/orm/reference/prisma-cli-reference#examples-14
Prisma CLI reference | Prisma Documentation
This page gives an overview of all available Prisma CLI commands, explains their options and shows numerous usage examples.
npx prisma migrate diff \
--from-url "$DATABASE_URL" \
--to-migrations ./prisma/migrations \
--shadow-database-url $SHADOW_DATABASE_URL \
--script > script.sql
I run this and I am getting this error:
Seems like my $DATABASE_URL isn't being picked up and when I hard coded it I get this:
Error: P1013
The provided database string is invalid. relative URL without a base in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
Connection URLs (Reference) | Prisma Documentation
Learn about the format and syntax Prisma ORM uses for defining database connection URLs for PostgreSQL, MySQL and SQLite.
Also, I am using mysql with railway if that helps
Any clues or suggestions? @Nurul (Prisma)
Can you try passing your actual connection string instead of "$DATABASE_URL", so something like:
I ran that code with my db value and I got this again... seems like it's not picking up my variables for some reason...
Ran it again from another terminal and I got this:
Error: P1013
Gonna check it out
Whenver I use the MYSQL_PRVIATVE_URL value, from railway for the mysql database, instead of the MYSQL_URL, I get this error:
Note that my env has
DATABASE_URL=MYSQL_URL
am I supposed to be using MYSQL_PRIVATE_URL
Also note I have development and production databases in my railway set up