1414
1515namespace Doctrine \Bundle \MigrationsBundle \Command ;
1616
17- use Symfony \Component \Console \Input \InputInterface ;
18- use Symfony \Component \Console \Output \OutputInterface ;
19- use Symfony \Component \Console \Input \InputOption ;
2017use Doctrine \Bundle \DoctrineBundle \Command \Proxy \DoctrineCommandHelper ;
2118use Doctrine \DBAL \Migrations \Tools \Console \Command \DiffCommand ;
19+ use Doctrine \DBAL \Sharding \PoolingShardConnection ;
20+ use Symfony \Component \Console \Input \InputInterface ;
21+ use Symfony \Component \Console \Input \InputOption ;
22+ use Symfony \Component \Console \Output \OutputInterface ;
2223
2324/**
2425 * Command for generate migration classes by comparing your current database schema
@@ -36,13 +37,23 @@ protected function configure()
3637 $ this
3738 ->setName ('doctrine:migrations:diff ' )
3839 ->addOption ('em ' , null , InputOption::VALUE_OPTIONAL , 'The entity manager to use for this command. ' )
40+ ->addOption ('shard ' , null , InputOption::VALUE_REQUIRED , 'The shard connection to use for this command. ' )
3941 ;
4042 }
4143
4244 public function execute (InputInterface $ input , OutputInterface $ output )
4345 {
4446 DoctrineCommandHelper::setApplicationEntityManager ($ this ->getApplication (), $ input ->getOption ('em ' ));
4547
48+ if ($ input ->getOption ('shard ' )) {
49+ $ connection = $ this ->getApplication ()->getHelperSet ()->get ('db ' )->getConnection ();
50+ if (!$ connection instanceof PoolingShardConnection) {
51+ throw new \LogicException (sprintf ("Connection of EntityManager '%s' must implements shards configuration. " , $ input ->getOption ('em ' )));
52+ }
53+
54+ $ connection ->connect ($ input ->getOption ('shard ' ));
55+ }
56+
4657 $ configuration = $ this ->getMigrationConfiguration ($ input , $ output );
4758 DoctrineCommand::configureMigrations ($ this ->getApplication ()->getKernel ()->getContainer (), $ configuration );
4859
0 commit comments