Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate sharding functionality #1508

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 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,13 @@ 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',
'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.',
self::class
);

foreach ($shards as $i => $shard) {
if ($shard['id'] === (int) $input->getOption('shard')) {
// Select sharded database
Expand All @@ -101,6 +109,12 @@ 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',
'Using a DBAL connection of type "%s" is deprecated. DBAL 3 does not support shards anymore.',
PoolingShardConnection::class
);
} else {
$tmpConnection->connect();
}
Expand Down
8 changes: 8 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,13 @@ protected function getEntityManager($name, $shardId = null)
$manager = $this->getDoctrine()->getManager($name);

if ($shardId) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Passing a "shardId" argument to "%s" is deprecated. DBAL 3 does not support shards anymore.',
__METHOD__
);

if (! $manager instanceof EntityManagerInterface) {
throw new LogicException(sprintf('Sharding is supported only in EntityManager of instance "%s".', EntityManagerInterface::class));
}
Expand Down
8 changes: 8 additions & 0 deletions Command/DropDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function array_merge;
use function in_array;
use function sprintf;
use function trigger_deprecation;

/**
* Database tool allows you to easily drop your configured databases.
Expand Down Expand Up @@ -86,6 +87,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// Default select global
$params = array_merge($params, $params['global'] ?? []);
if ($input->getOption('shard')) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.',
self::class
);

foreach ($shards as $shard) {
if ($shard['id'] === (int) $input->getOption('shard')) {
// Select sharded database
Expand Down
10 changes: 10 additions & 0 deletions Command/ImportMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use function mkdir;
use function sprintf;
use function str_replace;
use function trigger_deprecation;

/**
* Import Doctrine ORM metadata mapping information from an existing database.
Expand Down Expand Up @@ -120,6 +121,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$exporter->setEntityGenerator($entityGenerator);
}

if ($input->getOption('shard')) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.',
self::class
);
}

$em = $this->getEntityManager($input->getOption('em'), $input->getOption('shard'));

$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
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
7 changes: 7 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,12 @@ 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',
'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