Skip to content

Commit 1e598fb

Browse files
jfrochesamrose
andauthored
feat: support multiple versions of the pg_stat_monitor extension (#1683)
* feat: support multiple versions of the pg_stat_monitor extension Build multiple versions of the pg_stat_monitor extension on different PostgreSQL versions. Add test for the extensions and their upgrade on PostgreSQL 15 and 17. * feat: rebase on develop and suffix for testing * feat: use default nixos extension test And run pg_regress tests for pg_stat_monitor as part of the unified extension tests --------- Co-authored-by: Sam Rose <[email protected]>
1 parent 99dabf4 commit 1e598fb

File tree

4 files changed

+113
-28
lines changed

4 files changed

+113
-28
lines changed

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.072-orioledb"
14-
postgres17: "17.6.1.051"
15-
postgres15: "15.14.1.051"
13+
postgresorioledb-17: "17.5.1.073-orioledb"
14+
postgres17: "17.6.1.052"
15+
postgres15: "15.14.1.052"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.19.0

nix/ext/pg_stat_monitor.nix

Lines changed: 89 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,103 @@
33
stdenv,
44
fetchFromGitHub,
55
postgresql,
6+
buildEnv,
67
}:
7-
8-
stdenv.mkDerivation rec {
8+
let
99
pname = "pg_stat_monitor";
10-
version = "2.1.0";
1110

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

14-
src = fetchFromGitHub {
15-
owner = "percona";
16-
repo = pname;
17-
rev = "refs/tags/${version}";
18-
hash = "sha256-STJVvvrLVLe1JevNu6u6EftzAWv+X+J8lu66su7Or2s=";
19-
};
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 value.revision) supportedVersions
25+
);
26+
27+
# Build function for individual versions
28+
build =
29+
version: hash: revision:
30+
stdenv.mkDerivation rec {
31+
inherit pname version;
32+
33+
buildInputs = [ postgresql ];
34+
35+
src = fetchFromGitHub {
36+
owner = "percona";
37+
repo = pname;
38+
rev = "refs/tags/${revision}";
39+
inherit hash;
40+
};
41+
42+
makeFlags = [ "USE_PGXS=1" ];
43+
44+
installPhase = ''
45+
mkdir -p $out/{lib,share/postgresql/extension}
46+
47+
# Install shared library with version suffix
48+
mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
49+
50+
# Create version-specific control file
51+
sed -e "/^default_version =/d" \
52+
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}-${version}'|" \
53+
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
54+
55+
# For the latest version, create default control file and symlink and copy SQL upgrade scripts
56+
if [[ "${version}" == "${latestVersion}" ]]; then
57+
{
58+
echo "default_version = '${version}'"
59+
cat $out/share/postgresql/extension/${pname}--${version}.control
60+
} > $out/share/postgresql/extension/${pname}.control
61+
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
62+
cp *.sql $out/share/postgresql/extension
63+
else
64+
mv ./pg_stat_monitor--${version}.sql.in $out/share/postgresql/extension/pg_stat_monitor--${version}.sql
65+
fi
66+
'';
67+
68+
meta = with lib; {
69+
description = "Query Performance Monitoring Tool for PostgreSQL";
70+
homepage = "https://github.com/percona/${pname}";
71+
license = licenses.postgresql;
72+
broken = lib.versionOlder postgresql.version "15";
73+
inherit (postgresql.meta) platforms;
74+
};
75+
};
76+
in
77+
buildEnv {
78+
name = pname;
79+
paths = packages;
2080

21-
makeFlags = [ "USE_PGXS=1" ];
81+
pathsToLink = [
82+
"/lib"
83+
"/share/postgresql/extension"
84+
];
2285

23-
installPhase = ''
24-
mkdir -p $out/{lib,share/postgresql/extension}
86+
postBuild = ''
87+
# Verify all expected library files are present
88+
expectedFiles=${toString (numberOfVersions + 1)}
89+
actualFiles=$(ls -l $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)
2590
26-
cp *${postgresql.dlSuffix} $out/lib
27-
cp *.sql $out/share/postgresql/extension
28-
cp *.control $out/share/postgresql/extension
91+
if [[ "$actualFiles" != "$expectedFiles" ]]; then
92+
echo "Error: Expected $expectedFiles library files, found $actualFiles"
93+
echo "Files found:"
94+
ls -la $out/lib/*${postgresql.dlSuffix} || true
95+
exit 1
96+
fi
2997
'';
3098

31-
meta = with lib; {
32-
description = "Query Performance Monitoring Tool for PostgreSQL";
33-
homepage = "https://github.com/percona/${pname}";
34-
platforms = postgresql.meta.platforms;
35-
license = licenses.postgresql;
36-
broken = lib.versionOlder postgresql.version "15";
99+
passthru = {
100+
inherit versions numberOfVersions;
101+
pname = "${pname}-all";
102+
version =
103+
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
37104
};
38105
}

nix/ext/tests/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,13 @@ builtins.listToAttrs (
217217
"hypopg"
218218
"index_advisor"
219219
"pg_cron"
220-
"pg_hashids"
221220
"pg_graphql"
221+
"pg_hashids"
222222
"pg_jsonschema"
223223
"pg_net"
224-
"pgaudit"
224+
"pg_stat_monitor"
225225
"pg_tle"
226+
"pgaudit"
226227
"vector"
227228
"wal2json"
228229
"wrappers"

nix/ext/versions.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,23 @@
749749
"hash": "sha256-wfjiLkx+S3zVrAynisX1GdazueVJ3EOwQEPcgUQt7eA="
750750
}
751751
},
752+
"pg_stat_monitor": {
753+
"1.0": {
754+
"postgresql": [
755+
"15"
756+
],
757+
"revision": "1.0.1",
758+
"hash": "sha256-sQEpIknAFOmvNTX2G23X4BvMdy3Ms7sXx7hLZt8jyUk="
759+
},
760+
"2.1": {
761+
"postgresql": [
762+
"15",
763+
"17"
764+
],
765+
"revision": "2.1.0",
766+
"hash": "sha256-STJVvvrLVLe1JevNu6u6EftzAWv+X+J8lu66su7Or2s="
767+
}
768+
},
752769
"pg_tle": {
753770
"1.0.1": {
754771
"postgresql": [
@@ -796,4 +813,4 @@
796813
"hash": "sha256-+QoACPCKiFfuT2lJfSUmgfzC5MXf75KpSoc2PzPxKyM="
797814
}
798815
}
799-
}
816+
}

0 commit comments

Comments
 (0)