Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 00037d8

Browse filesBrowse files
committed
bug #47070 [Messenger] Fix function name in TriggerSql on postgresql bridge to support table name with schema (zimny9932)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Messenger] Fix function name in TriggerSql on postgresql bridge to support table name with schema …support table name with schema | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46984 | License | MIT Allow use schema in table_name option when configure postgresql transport. There was a problem with procedure name in getTriggerSql function in Symfony\Component\Messenger\Bridge\Doctrine\Transport\PostgreSqlConnection. Commits ------- 64e7c9b [Messenger] Fix function name in TriggerSql on postgresql bridge to support table name with schema
2 parents 2a4125f + 64e7c9b commit 00037d8
Copy full SHA for 00037d8

File tree

2 files changed

+30
-4
lines changed
Filter options

2 files changed

+30
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/PostgreSqlConnectionTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ public function testGetExtraSetupSql()
5858
$this->assertStringNotContainsString('COMMIT;', $sql);
5959
}
6060

61+
public function testTransformTableNameWithSchemaToValidProcedureName()
62+
{
63+
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);
64+
$connection = new PostgreSqlConnection(['table_name' => 'schema.queue_table'], $driverConnection);
65+
66+
$table = new Table('schema.queue_table');
67+
$table->addOption('_symfony_messenger_table_name', 'schema.queue_table');
68+
$sql = implode("\n", $connection->getExtraSetupSqlForTable($table));
69+
70+
$this->assertStringContainsString('CREATE OR REPLACE FUNCTION schema.notify_queue_table', $sql);
71+
$this->assertStringContainsString('FOR EACH ROW EXECUTE PROCEDURE schema.notify_queue_table()', $sql);
72+
}
73+
6174
public function testGetExtraSetupSqlWrongTable()
6275
{
6376
$driverConnection = $this->createMock(\Doctrine\DBAL\Connection::class);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/PostgreSqlConnection.php
+17-4Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,36 @@ public function getExtraSetupSqlForTable(Table $createdTable): array
118118

119119
private function getTriggerSql(): array
120120
{
121+
$functionName = $this->createTriggerFunctionName();
122+
121123
return [
122124
// create trigger function
123125
sprintf(<<<'SQL'
124-
CREATE OR REPLACE FUNCTION notify_%1$s() RETURNS TRIGGER AS $$
126+
CREATE OR REPLACE FUNCTION %1$s() RETURNS TRIGGER AS $$
125127
BEGIN
126-
PERFORM pg_notify('%1$s', NEW.queue_name::text);
128+
PERFORM pg_notify('%2$s', NEW.queue_name::text);
127129
RETURN NEW;
128130
END;
129131
$$ LANGUAGE plpgsql;
130132
SQL
131-
, $this->configuration['table_name']),
133+
, $functionName, $this->configuration['table_name']),
132134
// register trigger
133135
sprintf('DROP TRIGGER IF EXISTS notify_trigger ON %s;', $this->configuration['table_name']),
134-
sprintf('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON %1$s FOR EACH ROW EXECUTE PROCEDURE notify_%1$s();', $this->configuration['table_name']),
136+
sprintf('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON %1$s FOR EACH ROW EXECUTE PROCEDURE %2$s();', $this->configuration['table_name'], $functionName),
135137
];
136138
}
137139

140+
private function createTriggerFunctionName(): string
141+
{
142+
$tableConfig = explode('.', $this->configuration['table_name']);
143+
144+
if (1 === \count($tableConfig)) {
145+
return sprintf('notify_%1$s', $tableConfig[0]);
146+
}
147+
148+
return sprintf('%1$s.notify_%2$s', $tableConfig[0], $tableConfig[1]);
149+
}
150+
138151
private function unlisten()
139152
{
140153
if (!$this->listening) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.