Using Multiple Database in a single Symfony Application.
We need to trigger the MigrateCommand x times for x databases from a cron/hook when deploying a new version.
Current behavior
Note : Running this Command with the --conn option seems to not works.
So we use the --em option.
When calling the MigrateCommand multiple times FROM Command/Code the connection will be:
Because of this, the connection will always be the first "implemented".
In the end, calling this command in a loop and changing the connection/entityManager at each iteration won't work as untended.
How to reproduce
Have multiple connections
Have multiple EntityManagers
Run this command
<?php
namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
[AsCommand(
name: 'app:test',
)]
class TestCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$entityManagers = [
'client1',
'client2',
];
Bug Report
Summary
Using Multiple Database in a single Symfony Application. We need to trigger the MigrateCommand x times for x databases from a cron/hook when deploying a new version.
Current behavior
When calling the MigrateCommand multiple times FROM Command/Code the connection will be:
getted https://github.com/doctrine/migrations/blob/2f4b14968df1cb1c6e8beb724d142c4a8ddf2842/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php#L132
AND setted at the same time (if undefined) https://github.com/doctrine/migrations/blob/2f4b14968df1cb1c6e8beb724d142c4a8ddf2842/lib/Doctrine/Migrations/DependencyFactory.php#L158-L168
Because of this, the connection will always be the first "implemented". In the end, calling this command in a loop and changing the connection/entityManager at each iteration won't work as untended.
How to reproduce
namespace App\Command;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface;
[AsCommand(
)] class TestCommand extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { $entityManagers = [ 'client1', 'client2', ];
}