The simplest way to do this would just to use different environments for the migration and frontend processes.
Assuming you have the default Symfony 4 settings for doctrine:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
And that these settings are stored in your .env
files, then you could have a .env.migration
file in your root path with something like this:
DATABASE_URL=pgsql://usr_admin:admin_password@db_host:5432/db_name
This file wouldn't be read normally (and you should probably make sure this file is gitignored so it doesn't end in your repo). But when executing a migration, you would just do:
APP_ENV=migration bin/console doctrine:migration:migrate
and the command would run using the "admin" credentials instead of the main ones.