8000 [Messenger][Doctrine] Add test, oracle sequence suffixed with `_seq` · symfony/symfony@18eeb64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18eeb64

Browse files
committed
[Messenger][Doctrine] Add test, oracle sequence suffixed with _seq
1 parent 72d9ea1 commit 18eeb64

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 = $this->configuration['table_name'].'_seq';
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($this->configuration['table_name'].'_seq'.'.nextval');
547+
$idColumn->setDefault($this->configuration['table_name'].self::ORACLE_SEQUENCES_SUFFIX.'.nextval');
546548

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

0 commit comments

Comments
 (0)
0