Skip to content

Commit 211aaa4

Browse files
committed
bug #60211 [Messenger] Fix Oracle errors 'ORA-00955: Name is already used by an existing object' with Doctrine transport (atgitwk)
This PR was submitted for the 7.2 branch but it was squashed and merged into the 7.3 branch instead. Discussion ---------- [Messenger] Fix Oracle errors 'ORA-00955: Name is already used by an existing object' with Doctrine transport | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #59903 | License | MIT Initialization of MESSENGER objects causes an Oracle error when using `messenger:setup-transports`. For more explanation, please see issue #59903 Commits ------- 45c3203 [Messenger] Fix Oracle errors 'ORA-00955: Name is already used by an existing object' with Doctrine transport
2 parents 7c54399 + 45c3203 commit 211aaa4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,12 @@ public function testConfigureSchemaOracleSequenceNameSuffixed()
868868
{
869869
$driverConnection = $this->createMock(DBALConnection::class);
870870
$driverConnection->method('getDatabasePlatform')->willReturn(new OraclePlatform());
871+
872+
// Mock the result returned by executeQuery to be an Oracle version 12.1.0 or higher.
873+
$result = $this->createMock(Result::class);
874+
$result->method('fetchOne')->willReturn('12.1.0');
875+
$driverConnection->method('executeQuery')->willReturn($result);
876+
871877
$schema = new Schema();
872878

873879
$connection = new Connection(['table_name' => 'messenger_messages'], $driverConnection);

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ public function setup(): void
338338
throw new \TypeError(\sprintf('The table name must be an instance of "%s" or a string ("%s" given).', AbstractAsset::class, get_debug_type($tableName)));
339339
}
340340

341-
return $tableName === $this->configuration['table_name'];
341+
// SchemaAssetsFilter needs to match the messenger table name and also the messenger sequence name to make $schemaDiff work correctly in updateSchema()
342+
// This may also work for other databases if their sequence name is suffixed with '_seq', '_id_seq' or similar.
343+
return str_starts_with($tableName, $this->configuration['table_name']); // MESSENGER_MESSAGES*
342344
});
343345
$this->updateSchema();
344346
$configuration->setSchemaAssetsFilter($assetFilter);
@@ -569,9 +571,13 @@ private function addTableToSchema(Schema $schema): void
569571

570572
// We need to create a sequence for Oracle and set the id column to get the correct nextval
571573
if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
572-
$idColumn->setDefault($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX.'.nextval');
574+
$serverVersion = $this->driverConnection->executeQuery("SELECT version FROM product_component_version WHERE product LIKE 'Oracle Database%'")->fetchOne();
575+
if (version_compare($serverVersion, '12.1.0', '>=')) {
576+
$idColumn->setAutoincrement(false); // disable the creation of SEQUENCE and TRIGGER
577+
$idColumn->setDefault($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX.'.nextval');
573578

574-
$schema->createSequence($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX);
579+
$schema->createSequence($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX);
580+
}
575581
}
576582
}
577583

0 commit comments

Comments
 (0)