Skip to content

Commit 5bc387b

Browse files
committed
bug symfony#58557 [Doctrine][Messenger] Oracle sequences are suffixed with _seq (clem-rwan)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Doctrine][Messenger] Oracle sequences are suffixed with `_seq` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#58504 | License | MIT Generated sequences, by doctrine or in this case by the auto_setup of messenger, are suffixed with `_seq`. Commits ------- 6a17c04 [Doctrine][Messenger] Oracle sequences are suffixed with `_seq`
2 parents 4e1f1b8 + 6a17c04 commit 5bc387b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,4 +698,21 @@ class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::c
698698
];
699699
}
700700
}
701+
702+
public function testConfigureSchemaOracleSequenceNameSuffixed()
703+
{
704+
$driverConnection = $this->createMock(DBALConnection::class);
705+
$driverConnection->method('getDatabasePlatform')->willReturn(new OraclePlatform());
706+
$schema = new Schema();
707+
708+
$connection = new Connection(['table_name' => 'messenger_messages'], $driverConnection);
709+
$connection->configureSchema($schema, $driverConnection, fn () => true);
710+
711+
$expectedSuffix = '_seq';
712+
$sequences = $schema->getSequences();
713+
$this->assertCount(1, $sequences);
714+
$sequence = array_pop($sequences);
715+
$sequenceNameSuffix = substr($sequence->getName(), -strlen($expectedSuffix));
716+
$this->assertSame($expectedSuffix, $sequenceNameSuffix);
717+
}
701718
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class Connection implements ResetInterface
5353
'auto_setup' => true,
5454
];
5555

56+
private const ORACLE_SEQUENCES_SUFFIX = '_seq';
57+
5658
/**
5759
* Configuration of the connection.
5860
*
@@ -471,7 +473,7 @@ private function executeInsert(string $sql, array $parameters = [], array $types
471473
throw new TransportException('no id was returned by PostgreSQL from RETURNING clause.');
472474
}
473475
} elseif ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
474-
$sequenceName = 'seq_'.$this->configuration['table_name'];
476+
$sequenceName = $this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX;
475477

476478
$this->driverConnection->executeStatement($sql, $parameters, $types);
477479

@@ -542,9 +544,9 @@ private function addTableToSchema(Schema $schema): void
542544

543545
// We need to create a sequence for Oracle and set the id column to get the correct nextval
544546
if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
545-
$idColumn->setDefault('seq_'.$this->configuration['table_name'].'.nextval');
547+
$idColumn->setDefault($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX.'.nextval');
546548

547-
$schema->createSequence('seq_'.$this->configuration['table_name']);
549+
$schema->createSequence($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX);
548550
}
549551
}
550552

0 commit comments

Comments
 (0)