supabase-postgres.git / summary / log / commit / refs
commit 1e598fb3815bc115bacce6d0ef4ef54160a3eb9e
Author: Jean-François Roche <jfroche@pyxel.be>
Commit: GitHub <noreply@github.com>
Date: Sat Nov 15 00:16:45 2025 +0000
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 <samuel@supabase.io>
ansible/vars.yml | 6 +--
nix/ext/pg_stat_monitor.nix | 111 +++++++++++++++++++++++++++++++++++---------
nix/ext/tests/default.nix | 5 +-
nix/ext/versions.json | 19 +++++++-
4 files changed, 113 insertions(+), 28 deletions(-)
diff --git a/ansible/vars.yml b/ansible/vars.yml
index ef1362bf..eb248b55 100644
--- a/ansible/vars.yml
+++ b/ansible/vars.yml
@@ -10,9 +10,9 @@ postgres_major:
# Full version strings for each major version
postgres_release:
- postgresorioledb-17: "17.5.1.072-orioledb"
- postgres17: "17.6.1.051"
- postgres15: "15.14.1.051"
+ postgresorioledb-17: "17.5.1.073-orioledb"
+ postgres17: "17.6.1.052"
+ postgres15: "15.14.1.052"
# Non Postgres Extensions
pgbouncer_release: 1.19.0
diff --git a/nix/ext/pg_stat_monitor.nix b/nix/ext/pg_stat_monitor.nix
index 742e1c0a..2a2ce009 100644
--- a/nix/ext/pg_stat_monitor.nix
+++ b/nix/ext/pg_stat_monitor.nix
@@ -3,36 +3,103 @@
stdenv,
fetchFromGitHub,
postgresql,
+ buildEnv,
}:
-
-stdenv.mkDerivation rec {
+let
pname = "pg_stat_monitor";
- version = "2.1.0";
- buildInputs = [ postgresql ];
+ # Load version configuration from external file
+ allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
- src = fetchFromGitHub {
- owner = "percona";
- repo = pname;
- rev = "refs/tags/${version}";
- hash = "sha256-STJVvvrLVLe1JevNu6u6EftzAWv+X+J8lu66su7Or2s=";
- };
+ # Filter versions compatible with current PostgreSQL version
+ supportedVersions = lib.filterAttrs (
+ _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
+ ) allVersions;
+
+ # Derived version information
+ versions = lib.naturalSort (lib.attrNames supportedVersions);
+ latestVersion = lib.last versions;
+ numberOfVersions = builtins.length versions;
+ packages = builtins.attrValues (
+ lib.mapAttrs (name: value: build name value.hash value.revision) supportedVersions
+ );
+
+ # Build function for individual versions
+ build =
+ version: hash: revision:
+ stdenv.mkDerivation rec {
+ inherit pname version;
+
+ buildInputs = [ postgresql ];
+
+ src = fetchFromGitHub {
+ owner = "percona";
+ repo = pname;
+ rev = "refs/tags/${revision}";
+ inherit hash;
+ };
+
+ makeFlags = [ "USE_PGXS=1" ];
+
+ installPhase = ''
+ mkdir -p $out/{lib,share/postgresql/extension}
+
+ # Install shared library with version suffix
+ mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
+
+ # Create version-specific control file
+ sed -e "/^default_version =/d" \
+ -e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}-${version}'|" \
+ ${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
+
+ # For the latest version, create default control file and symlink and copy SQL upgrade scripts
+ if [[ "${version}" == "${latestVersion}" ]]; then
+ {
+ echo "default_version = '${version}'"
+ cat $out/share/postgresql/extension/${pname}--${version}.control
+ } > $out/share/postgresql/extension/${pname}.control
+ ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
+ cp *.sql $out/share/postgresql/extension
+ else
+ mv ./pg_stat_monitor--${version}.sql.in $out/share/postgresql/extension/pg_stat_monitor--${version}.sql
+ fi
+ '';
+
+ meta = with lib; {
+ description = "Query Performance Monitoring Tool for PostgreSQL";
+ homepage = "https://github.com/percona/${pname}";
+ license = licenses.postgresql;
+ broken = lib.versionOlder postgresql.version "15";
+ inherit (postgresql.meta) platforms;
+ };
+ };
+in
+buildEnv {
+ name = pname;
+ paths = packages;
- makeFlags = [ "USE_PGXS=1" ];
+ pathsToLink = [
+ "/lib"
+ "/share/postgresql/extension"
+ ];
- installPhase = ''
- mkdir -p $out/{lib,share/postgresql/extension}
+ postBuild = ''
+ # Verify all expected library files are present
+ expectedFiles=${toString (numberOfVersions + 1)}
+ actualFiles=$(ls -l $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)
- cp *${postgresql.dlSuffix} $out/lib
- cp *.sql $out/share/postgresql/extension
- cp *.control $out/share/postgresql/extension
+ if [[ "$actualFiles" != "$expectedFiles" ]]; then
+ echo "Error: Expected $expectedFiles library files, found $actualFiles"
+ echo "Files found:"
+ ls -la $out/lib/*${postgresql.dlSuffix} || true
+ exit 1
+ fi
'';
- meta = with lib; {
- description = "Query Performance Monitoring Tool for PostgreSQL";
- homepage = "https://github.com/percona/${pname}";
- platforms = postgresql.meta.platforms;
- license = licenses.postgresql;
- broken = lib.versionOlder postgresql.version "15";
+ passthru = {
+ inherit versions numberOfVersions;
+ pname = "${pname}-all";
+ version =
+ "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
};
}
diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix
index e99278e4..facd250f 100644
--- a/nix/ext/tests/default.nix
+++ b/nix/ext/tests/default.nix
@@ -217,12 +217,13 @@ builtins.listToAttrs (
"hypopg"
"index_advisor"
"pg_cron"
- "pg_hashids"
"pg_graphql"
+ "pg_hashids"
"pg_jsonschema"
"pg_net"
- "pgaudit"
+ "pg_stat_monitor"
"pg_tle"
+ "pgaudit"
"vector"
"wal2json"
"wrappers"
diff --git a/nix/ext/versions.json b/nix/ext/versions.json
index 5a33a4fc..d1a78336 100644
--- a/nix/ext/versions.json
+++ b/nix/ext/versions.json
@@ -749,6 +749,23 @@
"hash": "sha256-wfjiLkx+S3zVrAynisX1GdazueVJ3EOwQEPcgUQt7eA="
}
},
+ "pg_stat_monitor": {
+ "1.0": {
+ "postgresql": [
+ "15"
+ ],
+ "revision": "1.0.1",
+ "hash": "sha256-sQEpIknAFOmvNTX2G23X4BvMdy3Ms7sXx7hLZt8jyUk="
+ },
+ "2.1": {
+ "postgresql": [
+ "15",
+ "17"
+ ],
+ "revision": "2.1.0",
+ "hash": "sha256-STJVvvrLVLe1JevNu6u6EftzAWv+X+J8lu66su7Or2s="
+ }
+ },
"pg_tle": {
"1.0.1": {
"postgresql": [
@@ -796,4 +813,4 @@
"hash": "sha256-+QoACPCKiFfuT2lJfSUmgfzC5MXf75KpSoc2PzPxKyM="
}
}
-}
+}
\ No newline at end of file
[parent: 99dabf4dee44]