1

I have Symfony project with pgSQL DB.

I have two db users, one with select/update privileges for web (lets call it usr_web) and a second one with create/alter table for migrations (usr_admin).

I'd like to use usr_web for frontend of my web and usr_admin for running migrations via doctrine:migrations:migrate.

How can I achieve that?

yivi
  • 42,438
  • 18
  • 116
  • 138
Pavel Třupek
  • 898
  • 6
  • 19

1 Answers1

1

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.

yivi
  • 42,438
  • 18
  • 116
  • 138