From 6a17c04c6f0cb1a0d111dc09c6e0375175ecc3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Rwanyindo?= Date: Mon, 14 Oct 2024 09:55:16 +0200 Subject: [PATCH] [Doctrine][Messenger] Oracle sequences are suffixed with `_seq` --- .../Doctrine/Tests/Transport/ConnectionTest.php | 17 +++++++++++++++++ .../Bridge/Doctrine/Transport/Connection.php | 8 +++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php index 596ddb5c91fd1..2e4a5dccd32da 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php @@ -698,4 +698,21 @@ class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::c ]; } } + + public function testConfigureSchemaOracleSequenceNameSuffixed() + { + $driverConnection = $this->createMock(DBALConnection::class); + $driverConnection->method('getDatabasePlatform')->willReturn(new OraclePlatform()); + $schema = new Schema(); + + $connection = new Connection(['table_name' => 'messenger_messages'], $driverConnection); + $connection->configureSchema($schema, $driverConnection, fn () => true); + + $expectedSuffix = '_seq'; + $sequences = $schema->getSequences(); + $this->assertCount(1, $sequences); + $sequence = array_pop($sequences); + $sequenceNameSuffix = substr($sequence->getName(), -strlen($expectedSuffix)); + $this->assertSame($expectedSuffix, $sequenceNameSuffix); + } } diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php index 48592cbab6036..034291d8682b0 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php @@ -53,6 +53,8 @@ class Connection implements ResetInterface 'auto_setup' => true, ]; + private const ORACLE_SEQUENCES_SUFFIX = '_seq'; + /** * Configuration of the connection. * @@ -471,7 +473,7 @@ private function executeInsert(string $sql, array $parameters = [], array $types throw new TransportException('no id was returned by PostgreSQL from RETURNING clause.'); } } elseif ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) { - $sequenceName = 'seq_'.$this->configuration['table_name']; + $sequenceName = $this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX; $this->driverConnection->executeStatement($sql, $parameters, $types); @@ -542,9 +544,9 @@ private function addTableToSchema(Schema $schema): void // We need to create a sequence for Oracle and set the id column to get the correct nextval if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) { - $idColumn->setDefault('seq_'.$this->configuration['table_name'].'.nextval'); + $idColumn->setDefault($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX.'.nextval'); - $schema->createSequence('seq_'.$this->configuration['table_name']); + $schema->createSequence($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX); } }