Skip to content

Commit b8a12e1

Browse files
committed
fix(pgmq): replace drop_queue function if exists
We introduced a patch to override pgmq.drop_queue(TEXT) to conditionally drop objects only if they are part of the extension in `ansible/ansible/files/postgresql_extension_custom_scripts/pgmq/after-create.sql` . This script might have been installed on installations with existing 1.4.4 extensions. When the user tries to upgrade pgmq from 1.4.4 to 1.5.1, the upgrade process will fail because the upgrade script doesn't expect `pgmq.drop_queue(TEXT)` to exist. This change introduce the a patch to the pgmq extension to use `CREATE OR REPLACE FUNCTION` instead of `CREATE FUNCTION` for `pgmq.drop_queue(TEXT)` in the upgrade script from 1.4.5 to 1.5.0.
1 parent 1b91692 commit b8a12e1

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 31a9b2d736d8a85f113d592754f4832a0097bb2d Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Roche?= <[email protected]>
3+
Date: Thu, 9 Oct 2025 10:53:50 +0200
4+
Subject: [PATCH] fix: replace drop_queue function if exists
5+
6+
Function drop_queue might have been created by running `postgresql_extension_custom_scripts/pgmq/after-create.sql`
7+
on a previous version of the extension. In that case, running the migration script will fail because the function already exists.
8+
9+
We use `CREATE OR REPLACE FUNCTION` to avoid that issue.
10+
---
11+
pgmq-extension/sql/pgmq--1.4.5--1.5.0.sql | 2 +-
12+
1 file changed, 1 insertion(+), 1 deletion(-)
13+
14+
diff --git a/pgmq-extension/sql/pgmq--1.4.5--1.5.0.sql b/pgmq-extension/sql/pgmq--1.4.5--1.5.0.sql
15+
index 5754eed..de03788 100644
16+
--- a/pgmq-extension/sql/pgmq--1.4.5--1.5.0.sql
17+
+++ b/pgmq-extension/sql/pgmq--1.4.5--1.5.0.sql
18+
@@ -122,7 +122,7 @@ BEGIN
19+
END;
20+
$$ LANGUAGE plpgsql;
21+
22+
-CREATE FUNCTION pgmq.drop_queue(queue_name TEXT)
23+
+CREATE OR REPLACE FUNCTION pgmq.drop_queue(queue_name TEXT)
24+
RETURNS BOOLEAN AS $$
25+
DECLARE
26+
qtable TEXT := pgmq.format_table_name(queue_name, 'q');
27+
--
28+
2.51.0
29+

nix/ext/pgmq.nix renamed to nix/ext/pgmq/default.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let
99
pname = "pgmq";
1010

1111
# Load version configuration from external file
12-
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
12+
allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).${pname};
1313

1414
# Filter versions compatible with current PostgreSQL version
1515
supportedVersions = lib.filterAttrs (
@@ -37,6 +37,10 @@ let
3737
inherit hash;
3838
};
3939

40+
patches = lib.optionals (version == latestVersion) [
41+
./0001-fix-replace-drop_queue-function-if-exists.patch
42+
];
43+
4044
buildPhase = ''
4145
cd pgmq-extension
4246
'';

nix/packages/postgres.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
../ext/pgroonga.nix
2323
../ext/index_advisor.nix
2424
../ext/wal2json.nix
25-
../ext/pgmq.nix
25+
../ext/pgmq
2626
../ext/pg_repack.nix
2727
../ext/pg-safeupdate.nix
2828
../ext/plpgsql-check.nix

0 commit comments

Comments
 (0)