Override database connection string for Migrate (and other commands)
See original GitHub issueProblem
When using a connection pooler like PgBouncer, you need to use a non pooled connection URL for running Migrations. That is inconvenient, as Prisma Client and Migrate use the same datasource definition (with the same ENV var defining the connection string). So if you want to use the pooled connection for Prisma Client, running a Prisma Migrate command by default fails (see e.g. https://github.com/prisma/prisma/issues/6480).
The same is true when you want to use a different user for your Prisma Client that does not have permissions to CREATE, DROP or ALTER tables for example. As Prisma Client and Migrate use the same datasource definition (with the same ENV var defining the connection string), this is not trivial to get right and can lead to quite some confusion on the user side.
Suggested solution
We could have a dedicated ENV var that Migrate uses to override whatever is defined in the datasource. Naming could be PRISMA_MIGRATIONS_URL
or similar. Then we could tell people to set that to the un-pooled connection string when using a pooled connection for Prisma Client.
Alternatives
- Set a different ENV var value only when running Migrate
Additional context
Internal discussion: https://prisma-company.slack.com/archives/CL0AJEVSA/p1617976543036600
Issue Analytics
- State:
- Created 2 years ago
- Reactions:52
- Comments:11 (1 by maintainers)
Top GitHub Comments
Hi @janpio - just wanted to follow up on this again 😃 Any chance this could get prioritised? Would make migrations a lot easier.
The workaround I was thinking of for now, is to override the database url in the migrate command only like:
in my CI
You could simply have a different host in the db definition as in
Note:
migration_url
is not supported, it’s a suggestion.