Skip to content

Commit c6002c4

Browse files
jfrochesamrose
andauthored
feat: support multiple versions of the rum extension (#1692)
* feat: support multiple versions of the rum extension Build multiple versions of the rum extension on different PostgreSQL versions. Add test for the extensions and their upgrade on PostgreSQL 15 and 17. * feat: multiversion rum * chore: bump for test * chore: bump to release --------- Co-authored-by: Sam Rose <[email protected]>
1 parent 20dc72e commit c6002c4

File tree

4 files changed

+101
-24
lines changed

4 files changed

+101
-24
lines changed

ansible/vars.yml

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

1010
# Full version strings for each major version
1111
postgres_release:
12-
postgresorioledb-17: "17.5.1.027-orioledb"
13-
postgres17: "17.6.1.006"
14-
postgres15: "15.14.1.006"
12+
postgresorioledb-17: "17.5.1.028-orioledb"
13+
postgres17: "17.6.1.007"
14+
postgres15: "15.14.1.007"
1515

1616
# Non Postgres Extensions
1717
pgbouncer_release: "1.19.0"

nix/checks.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
pgpkg:
2828
let
2929
pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP;
30-
pg_regress = self'.packages.pg_regress;
30+
inherit (self'.packages) pg_regress;
3131
getkey-script = pkgs.stdenv.mkDerivation {
3232
name = "pgsodium-getkey";
3333
buildCommand = ''

nix/ext/rum.nix

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,100 @@
33
stdenv,
44
fetchFromGitHub,
55
postgresql,
6+
buildEnv,
67
}:
7-
8-
stdenv.mkDerivation rec {
8+
let
99
pname = "rum";
10-
version = "1.3.14";
1110

12-
src = fetchFromGitHub {
13-
owner = "postgrespro";
14-
repo = "rum";
15-
rev = version;
16-
hash = "sha256-VsfpxQqRBu9bIAP+TfMRXd+B3hSjuhU2NsutocNiCt8=";
17-
};
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 value.revision) supportedVersions
25+
);
26+
27+
# Build function for individual versions
28+
build =
29+
version: hash: revision:
30+
stdenv.mkDerivation {
31+
inherit pname version;
32+
33+
src = fetchFromGitHub {
34+
owner = "postgrespro";
35+
repo = "rum";
36+
rev = revision;
37+
inherit hash;
38+
};
39+
40+
buildInputs = [ postgresql ];
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+
fi
64+
'';
65+
66+
meta = with lib; {
67+
description = "Full text search index method for PostgreSQL";
68+
homepage = "https://github.com/postgrespro/rum";
69+
license = licenses.postgresql;
70+
inherit (postgresql.meta) platforms;
71+
};
72+
};
73+
in
74+
buildEnv {
75+
name = pname;
76+
paths = packages;
1877

19-
buildInputs = [ postgresql ];
78+
pathsToLink = [
79+
"/lib"
80+
"/share/postgresql/extension"
81+
];
2082

21-
makeFlags = [ "USE_PGXS=1" ];
83+
postBuild = ''
84+
# Verify all expected library files are present
85+
expectedFiles=${toString (numberOfVersions + 1)}
86+
actualFiles=$(ls -l $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)
2287
23-
installPhase = ''
24-
install -D -t $out/lib *${postgresql.dlSuffix}
25-
install -D -t $out/share/postgresql/extension *.control
26-
install -D -t $out/share/postgresql/extension *.sql
88+
if [[ "$actualFiles" != "$expectedFiles" ]]; then
89+
echo "Error: Expected $expectedFiles library files, found $actualFiles"
90+
echo "Files found:"
91+
ls -la $out/lib/*${postgresql.dlSuffix} || true
92+
exit 1
93+
fi
2794
'';
2895

29-
meta = with lib; {
30-
description = "Full text search index method for PostgreSQL";
31-
homepage = "https://github.com/postgrespro/rum";
32-
license = licenses.postgresql;
33-
platforms = postgresql.meta.platforms;
96+
passthru = {
97+
inherit versions numberOfVersions;
98+
pname = "${pname}-all";
99+
version =
100+
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
34101
};
35102
}

nix/ext/versions.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@
130130
],
131131
"hash": "sha256-Cpi2iASi1QJoED0Qs1dANqg/BNZTsz5S+pw8iYyW03Y="
132132
}
133+
},
134+
"rum": {
135+
"1.3": {
136+
"postgresql": [
137+
"15",
138+
"17"
139+
],
140+
"hash": "sha256-VsfpxQqRBu9bIAP+TfMRXd+B3hSjuhU2NsutocNiCt8=",
141+
"revision": "1.3.14"
142+
}
133143
},
134144
"timescaledb": {
135145
"2.9.1": {

0 commit comments

Comments
 (0)