Skip to content

Commit

Permalink
deprecate sharding functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed Apr 15, 2022
1 parent 5f64c8e commit 7d339bc
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Command/CreateDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function array_merge;
use function in_array;
use function sprintf;
use function trigger_deprecation;

/**
* Database tool allows you to easily create your configured databases.
Expand Down Expand Up @@ -78,6 +79,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$params = array_merge($params, $params['global'] ?? []);
unset($params['global']['dbname'], $params['global']['path'], $params['global']['url']);
if ($input->getOption('shard')) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'The "shard" option is deprecated. DBAL 3 does not support shards anymore.'
);

foreach ($shards as $i => $shard) {
if ($shard['id'] === (int) $input->getOption('shard')) {
// Select sharded database
Expand All @@ -101,6 +108,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$tmpConnection = DriverManager::getConnection($params);
if ($tmpConnection instanceof PoolingShardConnection) {
$tmpConnection->connect($input->getOption('shard'));
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
sprintf('Using a DBAL connection of type "%s" is deprecated. DBAL 3 does not support shards anymore.', PoolingShardConnection::class)
);
} else {
$tmpConnection->connect();
}
Expand Down
7 changes: 7 additions & 0 deletions Command/DoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Console\Command\Command;

use function sprintf;
use function trigger_deprecation;

/**
* Base class for Doctrine console commands to extend from.
Expand Down Expand Up @@ -61,6 +62,12 @@ protected function getEntityManager($name, $shardId = null)
$manager = $this->getDoctrine()->getManager($name);

if ($shardId) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'The "shardId" argument is deprecated. DBAL 3 does not support shards anymore.'
);

if (! $manager instanceof EntityManagerInterface) {
throw new LogicException(sprintf('Sharding is supported only in EntityManager of instance "%s".', EntityManagerInterface::class));
}
Expand Down
21 changes: 18 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,21 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
->scalarNode('server_version')->end()
->scalarNode('driver_class')->end()
->scalarNode('wrapper_class')->end()
->scalarNode('shard_manager_class')->end()
->scalarNode('shard_choser')->end()
->scalarNode('shard_choser_service')->end()
->scalarNode('shard_manager_class')
->setDeprecated(
...$this->getDeprecationMsg('The "shard_manager_class" configuration is deprecated and not supported anymore using DBAL 3.', '2.7')
)
->end()
->scalarNode('shard_choser')
->setDeprecated(
...$this->getDeprecationMsg('The "shard_choser" configuration is deprecated and not supported anymore using DBAL 3.', '2.7')
)
->end()
->scalarNode('shard_choser_service')
->setDeprecated(
...$this->getDeprecationMsg('The "shard_choser_service" configuration is deprecated and not supported anymore using DBAL 3.', '2.7')
)
->end()
->booleanNode('keep_slave')
->setDeprecated(
...$this->getDeprecationMsg('The "keep_slave" configuration key is deprecated since doctrine-bundle 2.2. Use the "keep_replica" configuration key instead.', '2.2')
Expand Down Expand Up @@ -222,6 +234,9 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition
$shardNode = $connectionNode
->children()
->arrayNode('shards')
->setDeprecated(
...$this->getDeprecationMsg('The "shards" configuration is deprecated and not supported anymore using DBAL 3.', '2.7')
)
->prototype('array');

$shardNode
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
use function reset;
use function sprintf;
use function str_replace;
use function trigger_deprecation;

use const PHP_VERSION_ID;

Expand Down Expand Up @@ -277,6 +278,11 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder

// Create a shard_manager for this connection
if (isset($options['shards'])) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
sprintf('Using shards for connection "%s" is deprecated. DBAL 3 does not support shards anymore.', $name)
);
$shardManagerDefinition = new Definition($options['shardManagerClass'], [new Reference($connectionId)]);
$container->setDefinition(sprintf('doctrine.dbal.%s_shard_manager', $name), $shardManagerDefinition);
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/Command/CreateDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public function testExecute(): void
);
}

/** @dataProvider provideShardOption */
/**
* @group legacy
* @dataProvider provideShardOption
*/
public function testExecuteWithShardAlias(string $shardOption): void
{
$connectionName = 'default';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function testDbalLoadSingleMasterSlaveConnection(): void
$this->assertEquals(['engine' => 'InnoDB'], $param['defaultTableOptions']);
}

/** @group legacy */
public function testDbalLoadPoolShardingConnection(): void
{
$container = $this->loadContainer('dbal_service_pool_sharding_connection');
Expand Down
1 change: 1 addition & 0 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ public static function cacheConfigurationProvider(): array
];
}

/** @group legacy */
public function testShardManager(): void
{
$container = $this->getContainer();
Expand Down

0 comments on commit 7d339bc

Please sign in to comment.