question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override database connection string for Migrate (and other commands)

See original GitHub issue

Problem

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:open
  • Created 2 years ago
  • Reactions:52
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
dac09commented, Jul 7, 2021

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

DATABASE_URL=$MIGRATE_DB_URL yarn prisma db migrate prod
6reactions
bingomanateecommented, Jul 28, 2022

You could simply have a different host in the db definition as in

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
  migration_url      = env("MIGRATION_DATABASE_URL")
}

Note: migration_url is not supported, it’s a suggestion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change connection string on command line to update ...
When I create a new tenant, I want to change connection string, add migration on it and then update. From command line, add...
Read more >
Change High Availability Database connection string on ...
Hello Does anyone know how to change or if its even possible to Availability Database connection string on Windows Server 2016.
Read more >
Code-Based Migration in Entity Framework 6
Update-Database: Executes the last migration file created by the ... To use code-based migrations, first execute the enable-migrations command in the ...
Read more >
How to use PowerShell to Change XenDesktop SQL ...
Citrix offers several PowerShell scripts that update XenApp and XenDesktop database connection strings when you are using SQL Server high availability ...
Read more >
Multiple databases | Django documentation
Most other django-admin commands that interact with the database operate in the same way as migrate – they only ever operate on one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found