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
Nurul
Nurul5w ago
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
deme4447
deme4447OP5w ago
Correct, I think I missed that guide but after reading it I had a question about this part:
No description
deme4447
deme4447OP5w ago
"1. Reset the contents of your local ./prisma/migrations..." By reset, does that mean delete all my migrations in the migrations folder?
No description
Nurul
Nurul4w ago
It means that the migrations on your GitHub main branch and your local migrations should look same.
deme4447
deme4447OP4w ago
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:
npx prisma migrate dev --name squashed_migrations
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "railway" at "autorack.proxy.rlwy.net:14917"
Already in sync, no schema change or pending migration was found.

✔ Generated Prisma Client (v6.1.0) to .\node_modules\@prisma\client in 66ms
npx prisma migrate dev --name squashed_migrations
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "railway" at "autorack.proxy.rlwy.net:14917"
Already in sync, no schema change or pending migration was found.

✔ Generated Prisma Client (v6.1.0) to .\node_modules\@prisma\client in 66ms
Any ideas on what I could be missing? Thanks for your time btw
deme4447
deme4447OP4w ago
This is what I get in vercel when I try to migrate deploy, thought that might help
No description
deme4447
deme4447OP4w ago
Just noticed I forgot to reply, doing it now in case that’s how you keep track of the questions
Nurul
Nurul4w ago
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.
No description
deme4447
deme4447OP4w ago
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:
npx prisma migrate diff \ --from-url "$DATABASE_URL" \ --to-migrations ./prisma/migrations \ --shadow-database-url $SHADOW_DATABASE_URL \ --script > script.sql
Error:
0 `--from-...` parameter(s) provided. 1 must be provided.
npx prisma migrate diff \ --from-url "$DATABASE_URL" \ --to-migrations ./prisma/migrations \ --shadow-database-url $SHADOW_DATABASE_URL \ --script > script.sql
Error:
0 `--from-...` parameter(s) provided. 1 must be provided.
deme4447
deme4447OP4w ago
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.
deme4447
deme4447OP3w ago
Also, I am using mysql with railway if that helps Any clues or suggestions? @Nurul (Prisma)
Nurul
Nurul2w ago
Can you try passing your actual connection string instead of "$DATABASE_URL", so something like:
npx prisma migrate diff \ --from-url "mysql://user:password@host/db" \ --to-migrations ./prisma/migrations \ --shadow-database-url $SHADOW_DATABASE_URL \ --script > script.sql
npx prisma migrate diff \ --from-url "mysql://user:password@host/db" \ --to-migrations ./prisma/migrations \ --shadow-database-url $SHADOW_DATABASE_URL \ --script > script.sql
deme4447
deme4447OP2w ago
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...
0 `--from-...` parameter(s) provided. 1 must be provided.
0 `--to-...` parameter(s) provided. 1 must be provided.
0 `--from-...` parameter(s) provided. 1 must be provided.
0 `--to-...` parameter(s) provided. 1 must be provided.
Ran it again from another terminal and I got 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.
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.
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:
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.
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.
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

Did you find this page helpful?