diff --git a/src/Symfony/Component/Messenger/CHANGELOG.md b/src/Symfony/Component/Messenger/CHANGELOG.md index 7ae4a2b63c7c7..0b08734526bbc 100644 --- a/src/Symfony/Component/Messenger/CHANGELOG.md +++ b/src/Symfony/Component/Messenger/CHANGELOG.md @@ -3,7 +3,7 @@ CHANGELOG 4.4.0 ----- - + * Added option for forcing mysql indexes creation for doctrine transport * Added support for auto trimming of Redis streams. * `InMemoryTransport` handle acknowledged and rejected messages. * Made all dispatched worker event classes final. diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php index 5bc7dddcd2934..69e8f71588012 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php @@ -414,7 +414,7 @@ public function providePlatformSql(): iterable /** * @dataProvider setupIndicesProvider */ - public function testSetupIndices(string $platformClass, array $expectedIndices) + public function testSetupIndices(string $platformClass, array $expectedIndices, array $options = []) { $driverConnection = $this->createMock(DBALConnection::class); $driverConnection->method('getConfiguration')->willReturn(new Configuration()); @@ -448,7 +448,7 @@ public function testSetupIndices(string $platformClass, array $expectedIndices) ->willReturn([]); $driverConnection->method('getDatabasePlatform')->willReturn($platformMock); - $connection = new Connection([], $driverConnection); + $connection = new Connection($options, $driverConnection); $connection->setup(); } @@ -459,6 +459,12 @@ public function setupIndicesProvider(): iterable [['delivered_at']], ]; + yield 'MySQL with forced index' => [ + MySQL57Platform::class, + [['queue_name'], ['available_at'], ['delivered_at']], + ['force_indexes_creation' => true], + ]; + yield 'Other platforms' => [ AbstractPlatform::class, [['queue_name'], ['available_at'], ['delivered_at']], diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php index 48d00c4be5ede..efe2ff59dc1d2 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -41,6 +41,7 @@ class Connection 'queue_name' => 'default', 'redeliver_timeout' => 3600, 'auto_setup' => true, + 'force_indexes_creation' => false, ]; /** @@ -53,6 +54,7 @@ class Connection * * queue_name: name of the queue * * redeliver_timeout: Timeout before redeliver messages still in handling state (i.e: delivered_at is not null and message is still in table). Default 3600 * * auto_setup: Whether the table should be created automatically during send / get. Default : true + * * force_indexes_creation: Whether indexes should be created also on mysql */ private $configuration = []; private $driverConnection; @@ -397,7 +399,7 @@ private function getSchema(): Schema ->setNotnull(false); $table->setPrimaryKey(['id']); // No indices on queue_name and available_at on MySQL to prevent deadlock issues when running multiple consumers. - if (!$this->driverConnection->getDatabasePlatform() instanceof MySqlPlatform) { + if ($this->configuration['force_indexes_creation'] || !$this->driverConnection->getDatabasePlatform() instanceof MySqlPlatform) { $table->addIndex(['queue_name']); $table->addIndex(['available_at']); }