Skip to content

Commit 0940043

Browse files
committed
bug #40336 [Messenger] Doctrine setup with migrations (Nyholm)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [Messenger] Doctrine setup with migrations | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | | Deprecations? | no | Tickets | Fix #40130 | License | MIT | Doc PR | This PR reverts parts of #40055. When running these commands, You do need to be in a transaction: - `doctrine:schema:create` - `messenger:setup-transports` - `doctrine:migrations:diff` and `doctrine:migrations:migrate` Commits ------- 3371e1c [Messenger] Doctrine setup with migrations
2 parents 5fea563 + 3371e1c commit 0940043

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,19 @@ public function testGetExtraSetupSql()
4949

5050
$table = new Table('queue_table');
5151
$table->addOption('_symfony_messenger_table_name', 'queue_table');
52-
$this->assertStringContainsString('CREATE TRIGGER', implode("\n", $connection->getExtraSetupSqlForTable($table)));
52+
$sql = implode("\n", $connection->getExtraSetupSqlForTable($table));
53+
54+
/*
55+
* We need to start a transaction for the following commands to work properly:
56+
* doctrine:schema:create
57+
* messenger:setup-transports
58+
* doctrine:migrations:diff and doctrine:migrations:migrate
59+
*/
60+
$this->assertStringContainsString('BEGIN;', $sql);
61+
$this->assertStringContainsString('CREATE TRIGGER', $sql);
62+
63+
// We MUST NOT commit, that will mess with the PDO in PHP 8
64+
$this->assertStringNotContainsString('COMMIT;', $sql);
5365
}
5466

5567
public function testGetExtraSetupSqlWrongTable()

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function setup(): void
8787
{
8888
parent::setup();
8989

90-
$this->executeStatement('BEGIN;'.implode("\n", $this->getTriggerSql()).'COMMIT;');
90+
$this->executeStatement(implode("\n", $this->getTriggerSql()));
9191
}
9292

9393
/**
@@ -109,6 +109,7 @@ public function getExtraSetupSqlForTable(Table $createdTable): array
109109
private function getTriggerSql(): array
110110
{
111111
return [
112+
'BEGIN;',
112113
sprintf('LOCK TABLE %s;', $this->configuration['table_name']),
113114
// create trigger function
114115
sprintf(<<<'SQL'

0 commit comments

Comments
 (0)