Skip to content

Commit ba47876

Browse files
committed
feat: support multiple versions of the pgmq extension
Build multiple versions of the pgmq extension on different PostgreSQL versions. Add test for the extensions and their upgrade on PostgreSQL 15 and 17.
1 parent d584651 commit ba47876

File tree

9 files changed

+169
-45
lines changed

9 files changed

+169
-45
lines changed

ansible/files/postgresql_extension_custom_scripts/pgmq/after-create.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ begin
1818
physical backups everywhere
1919
*/
2020
-- Detach and delete the official function
21-
alter extension pgmq drop function pgmq.drop_queue;
22-
drop function pgmq.drop_queue;
21+
alter extension pgmq drop function pgmq.drop_queue(TEXT);
22+
drop function pgmq.drop_queue(TEXT);
2323

2424
-- Create and reattach the patched function
2525
CREATE FUNCTION pgmq.drop_queue(queue_name TEXT)
@@ -134,7 +134,7 @@ BEGIN
134134
END;
135135
$func$ LANGUAGE plpgsql;
136136

137-
alter extension pgmq add function pgmq.drop_queue;
137+
alter extension pgmq add function pgmq.drop_queue(TEXT);
138138

139139

140140
update pg_extension set extowner = 'postgres'::regrole where extname = 'pgmq';

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ postgres_major:
1010

1111
# Full version strings for each major version
1212
postgres_release:
13-
postgresorioledb-17: "17.5.1.035-orioledb"
14-
postgres17: "17.6.1.014"
15-
postgres15: "15.14.1.014"
13+
postgresorioledb-17: 17.5.1.035-orioledb-pgmq
14+
postgres17: 17.6.1.014-pgmq
15+
postgres15: 15.14.1.014-pgmq
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.19.0

nix/ext/pgmq.nix

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,90 @@
33
stdenv,
44
fetchFromGitHub,
55
postgresql,
6+
buildEnv,
67
}:
7-
8-
stdenv.mkDerivation rec {
8+
let
99
pname = "pgmq";
10-
version = "1.4.4";
11-
buildInputs = [ postgresql ];
12-
src = fetchFromGitHub {
13-
owner = "tembo-io";
14-
repo = pname;
15-
rev = "v${version}";
16-
hash = "sha256-z+8/BqIlHwlMnuIzMz6eylmYbSmhtsNt7TJf/CxbdVw=";
17-
};
1810

19-
buildPhase = ''
20-
cd pgmq-extension
21-
'';
11+
# Load version configuration from external file
12+
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
13+
14+
# Filter versions compatible with current PostgreSQL version
15+
supportedVersions = lib.filterAttrs (
16+
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
17+
) allVersions;
18+
19+
# Derived version information
20+
versions = lib.naturalSort (lib.attrNames supportedVersions);
21+
latestVersion = lib.last versions;
22+
numberOfVersions = builtins.length versions;
23+
packages = builtins.attrValues (
24+
lib.mapAttrs (name: value: build name value.hash) supportedVersions
25+
);
26+
27+
# Build function for individual versions
28+
build =
29+
version: hash:
30+
stdenv.mkDerivation rec {
31+
inherit pname version;
32+
buildInputs = [ postgresql ];
33+
src = fetchFromGitHub {
34+
owner = "tembo-io";
35+
repo = pname;
36+
rev = "v${version}";
37+
inherit hash;
38+
};
39+
40+
buildPhase = ''
41+
cd pgmq-extension
42+
'';
43+
44+
installPhase = ''
45+
runHook preInstall
46+
47+
mkdir -p $out/share/postgresql/extension
48+
49+
# Create versioned sql install script
50+
cp sql/${pname}.sql $out/share/postgresql/extension/${pname}--${version}.sql
51+
52+
# Create versioned control file with modified module path
53+
sed -e "/^default_version =/d" \
54+
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \
55+
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
56+
57+
# For the latest version, create default control file and symlink and copy SQL upgrade scripts
58+
if [[ "${version}" == "${latestVersion}" ]]; then
59+
{
60+
echo "default_version = '${version}'"
61+
cat $out/share/postgresql/extension/${pname}--${version}.control
62+
} > $out/share/postgresql/extension/${pname}.control
63+
cp sql/*.sql $out/share/postgresql/extension
64+
fi
65+
66+
runHook postInstall
67+
'';
2268

23-
installPhase = ''
24-
mkdir -p $out/{lib,share/postgresql/extension}
69+
meta = with lib; {
70+
description = "A lightweight message queue. Like AWS SQS and RSMQ but on Postgres.";
71+
homepage = "https://github.com/tembo-io/pgmq";
72+
maintainers = with maintainers; [ olirice ];
73+
inherit (postgresql.meta) platforms;
74+
license = licenses.postgresql;
75+
};
76+
};
77+
in
78+
buildEnv {
79+
name = pname;
80+
paths = packages;
2581

26-
mv sql/pgmq.sql $out/share/postgresql/extension/pgmq--${version}.sql
27-
cp sql/*.sql $out/share/postgresql/extension
28-
cp *.control $out/share/postgresql/extension
29-
'';
82+
pathsToLink = [
83+
"/share/postgresql/extension"
84+
];
3085

31-
meta = with lib; {
32-
description = "A lightweight message queue. Like AWS SQS and RSMQ but on Postgres.";
33-
homepage = "https://github.com/tembo-io/pgmq";
34-
maintainers = with maintainers; [ olirice ];
35-
platforms = postgresql.meta.platforms;
36-
license = licenses.postgresql;
86+
passthru = {
87+
inherit versions numberOfVersions;
88+
pname = "${pname}-all";
89+
version =
90+
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
3791
};
3892
}

nix/ext/tests/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ builtins.listToAttrs (
187187
"pg_cron"
188188
"pg_graphql"
189189
"pg_net"
190+
"pgmq"
190191
"vector"
191192
"wrappers"
192193
]

nix/ext/versions.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,21 @@
278278
"hash": "sha256-Cpi2iASi1QJoED0Qs1dANqg/BNZTsz5S+pw8iYyW03Y="
279279
}
280280
},
281+
"pgmq": {
282+
"1.4.4": {
283+
"postgresql": [
284+
"15"
285+
],
286+
"hash": "sha256-z+8/BqIlHwlMnuIzMz6eylmYbSmhtsNt7TJf/CxbdVw="
287+
},
288+
"1.5.1": {
289+
"postgresql": [
290+
"15",
291+
"17"
292+
],
293+
"hash": "sha256-IU+i6ONPwtgsFKdzya6E+222ualR66gkbb0lDr+7Rb8="
294+
}
295+
},
281296
"pgsodium": {
282297
"3.0.4": {
283298
"postgresql": [
@@ -403,7 +418,7 @@
403418
"hash": "sha256-JsZV+I4eRMypXTjGmjCtMBXDVpqTIPHQa28ogXncE/Q="
404419
}
405420
},
406-
"wrappers": {
421+
"wrappers": {
407422
"0.5.4": {
408423
"postgresql": [
409424
"15",

nix/tests/expected/pgmq.out

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ order by
160160
-------------+-------------------------------+----------
161161
pgmq | _belongs_to_pgmq | postgres
162162
pgmq | _ensure_pg_partman_installed | postgres
163+
pgmq | _extension_exists | postgres
163164
pgmq | _get_partition_col | postgres
164165
pgmq | _get_pg_partman_major_version | postgres
165166
pgmq | _get_pg_partman_schema | postgres
@@ -174,6 +175,7 @@ order by
174175
pgmq | delete | postgres
175176
pgmq | detach_archive | postgres
176177
pgmq | drop_queue | postgres
178+
pgmq | drop_queue | postgres
177179
pgmq | format_table_name | postgres
178180
pgmq | list_queues | postgres
179181
pgmq | metrics | postgres
@@ -183,8 +185,18 @@ order by
183185
pgmq | read | postgres
184186
pgmq | read_with_poll | postgres
185187
pgmq | send | postgres
188+
pgmq | send | postgres
189+
pgmq | send | postgres
190+
pgmq | send | postgres
191+
pgmq | send | postgres
192+
pgmq | send | postgres
193+
pgmq | send_batch | postgres
194+
pgmq | send_batch | postgres
195+
pgmq | send_batch | postgres
196+
pgmq | send_batch | postgres
197+
pgmq | send_batch | postgres
186198
pgmq | send_batch | postgres
187199
pgmq | set_vt | postgres
188200
pgmq | validate_queue_name | postgres
189-
(28 rows)
201+
(40 rows)
190202

0 commit comments

Comments
 (0)