0

In a Symfony project, I have these two dependencies installed:

    "doctrine/dbal": "^3.3",
    "doctrine/migrations": "^3.5",

I have several db connections defined in Symfony, one of them is:

  db.connection:
      class: Doctrine\DBAL\Connection
      public: true
      factory: Doctrine\DBAL\DriverManager::getConnection
      arguments:
        $params:
          driver: pdo_pgsql
          url: '%env(DB_URL)%'
          charset: UTF8

To run the migrations in the application I execute: vendor/bin/doctrine-migrations migrate --configuration=doctrine-config.php --db-configuration=doctrine-db.php

The content of doctrine-config.php is:

<?php

declare(strict_types=1);

return [
    'table_storage' => [
        'table_name' => 'doctrine_migration_versions',
        'version_column_name' => 'version',
        'version_column_length' => 1024,
        'executed_at_column_name' => 'executed_at',
        'execution_time_column_name' => 'execution_time'
    ],
    'migrations_paths' => [
        'Infrastructure\Doctrine\Migrations'
            => 'src/Infrastructure/Doctrine/Migrations'
    ],
    'all_or_nothing' => true,
    'transactional' => true,
    'check_database_platform' => true,
    'organize_migrations' => 'none',
    'connection' => null,
    'em' => null,
];

The content of doctrine-db.php is:

<?php

declare(strict_types=1);

use Doctrine\DBAL\DriverManager;

return DriverManager::getConnection([
    'diver' => 'pdo_pgsql',
    'url' => getenv('DB_URL'),
    'charset' => 'UTF8'
]);

I wonder if there is a way to reuse the defined connection db.connection when running the migration to avoid writing the file doctrine-db.php.

Thanks!

0 Answers0