Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3371e1c

Browse files
Nyholmfabpot
authored andcommitted
[Messenger] Doctrine setup with migrations
1 parent 82e3b17 commit 3371e1c

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

Lines changed: 13 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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)