Skip to content

Commit 9ea4128

Browse files
jfrochesamrose
authored andcommitted
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.
1 parent 20dc72e commit 9ea4128

File tree

4 files changed

+137
-21
lines changed

4 files changed

+137
-21
lines changed

nix/checks.nix

Lines changed: 8 additions & 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 = ''
@@ -309,13 +309,20 @@
309309
;
310310
}
311311
// pkgs.lib.optionalAttrs (system == "x86_64-linux") (
312+
<<<<<<< HEAD
312313
{
313314
devShell = self'.devShells.default;
314315
}
315316
// (import ./ext/tests {
316317
inherit self;
317318
inherit pkgs;
318319
})
320+
=======
321+
import ./ext/tests {
322+
inherit self;
323+
inherit pkgs;
324+
}
325+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
319326
);
320327
};
321328
}

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/tests/default.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ let
4343
};
4444
in
4545
pkg;
46+
<<<<<<< HEAD
4647
psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
4748
psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17;
49+
=======
50+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
4851
in
4952
self.inputs.nixpkgs.lib.nixos.runTest {
5053
name = pname;
@@ -67,22 +70,33 @@ let
6770

6871
services.postgresql = {
6972
enable = true;
73+
<<<<<<< HEAD
7074
package = psql_15;
75+
=======
76+
package = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
77+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
7178
enableTCPIP = true;
7279
initialScript = pkgs.writeText "init-postgres-with-password" ''
7380
CREATE USER test WITH PASSWORD 'secret';
7481
'';
7582
authentication = ''
7683
host test postgres samenet scram-sha-256
7784
'';
85+
<<<<<<< HEAD
7886
settings = (installedExtension "15").defaultSettings or { };
87+
=======
88+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
7989
};
8090

8191
networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ];
8292

8393
specialisation.postgresql17.configuration = {
8494
services.postgresql = {
95+
<<<<<<< HEAD
8596
package = lib.mkForce psql_17;
97+
=======
98+
package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17);
99+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
86100
};
87101

88102
systemd.services.postgresql-migrate = {
@@ -96,8 +110,13 @@ let
96110
};
97111
script =
98112
let
113+
<<<<<<< HEAD
99114
oldPostgresql = psql_15;
100115
newPostgresql = psql_17;
116+
=======
117+
oldPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
118+
newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17;
119+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
101120
oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}";
102121
newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}";
103122
in
@@ -132,9 +151,12 @@ let
132151
extension_name = "${pname}"
133152
support_upgrade = True
134153
pg17_configuration = "${pg17-configuration}"
154+
<<<<<<< HEAD
135155
ext_has_background_worker = ${
136156
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
137157
}
158+
=======
159+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
138160
139161
${builtins.readFile ./lib.py}
140162
@@ -152,10 +174,13 @@ let
152174
with subtest("Check the install of the last version of the extension"):
153175
last_version = test.check_install_last_version("15")
154176
177+
<<<<<<< HEAD
155178
if ext_has_background_worker:
156179
with subtest("Test switch_${pname}_version"):
157180
test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15")
158181
182+
=======
183+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
159184
with subtest("switch to postgresql 17"):
160185
server.succeed(
161186
f"{pg17_configuration}/bin/switch-to-configuration test >&2"
@@ -176,6 +201,7 @@ builtins.listToAttrs (
176201
}) nixFiles
177202
)
178203
// builtins.listToAttrs (
204+
<<<<<<< HEAD
179205
map
180206
(extName: {
181207
name = "ext-${extName}";
@@ -189,4 +215,10 @@ builtins.listToAttrs (
189215
"vector"
190216
"wrappers"
191217
]
218+
=======
219+
map (extName: {
220+
name = "ext-${extName}";
221+
value = extTest extName;
222+
}) [ "rum" ]
223+
>>>>>>> e93f70f1 (feat: support multiple versions of the rum extension)
192224
)

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)