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 c26d122

Browse filesBrowse files
committed
[Messenger] Create trigger function in specific schema
1 parent 4156f8e commit c26d122
Copy full SHA for c26d122

File tree

Expand file treeCollapse file tree

2 files changed

+18
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-6
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
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function testTransformTableNameWithSchemaToValidProcedureName()
6767
$table->addOption('_symfony_messenger_table_name', 'schema.queue_table');
6868
$sql = implode("\n", $connection->getExtraSetupSqlForTable($table));
6969

70-
$this->assertStringContainsString('CREATE OR REPLACE FUNCTION notify_schema_queue_table', $sql);
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);
7172
}
7273

7374
public function testGetExtraSetupSqlWrongTable()

‎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
+16-5Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,36 @@ public function getExtraSetupSqlForTable(Table $createdTable): array
118118

119119
private function getTriggerSql(): array
120120
{
121-
$functionName = str_replace('.', '_', $this->configuration['table_name']);
121+
$functionName = $this->createTriggerFunctionName();
122122

123123
return [
124124
// create trigger function
125125
sprintf(<<<'SQL'
126-
CREATE OR REPLACE FUNCTION notify_%1$s() RETURNS TRIGGER AS $$
126+
CREATE OR REPLACE FUNCTION %1$s() RETURNS TRIGGER AS $$
127127
BEGIN
128-
PERFORM pg_notify('%1$s', NEW.queue_name::text);
128+
PERFORM pg_notify('%2$s', NEW.queue_name::text);
129129
RETURN NEW;
130130
END;
131131
$$ LANGUAGE plpgsql;
132132
SQL
133-
, $functionName),
133+
, $functionName, $this->configuration['table_name']),
134134
// register trigger
135135
sprintf('DROP TRIGGER IF EXISTS notify_trigger ON %s;', $this->configuration['table_name']),
136-
sprintf('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON %1$s FOR EACH ROW EXECUTE PROCEDURE notify_%2$s();', $this->configuration['table_name'], $functionName),
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),
137137
];
138138
}
139139

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+
140151
private function unlisten()
141152
{
142153
if (!$this->listening) {

0 commit comments

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