Skip to content

Commit 5923e77

Browse files
authored
feat: support multiple versions of the pg_tle extension (#1756)
* feat: multiple versions for the pg_tle extension Build multiple versions of the pg_tle extension on different PostgreSQL versions. Add test for the extensions and their upgrade on PostgreSQL 15 and 17. * chore: add release suffix for testing * feat(pg_tle): use default nixos extension test And run pg_regress tests for pg_tle as part of the unified extension tests
1 parent 29dac20 commit 5923e77

File tree

4 files changed

+132
-36
lines changed

4 files changed

+132
-36
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.062-orioledb"
14-
postgres17: "17.6.1.041"
15-
postgres15: "15.14.1.041"
13+
postgresorioledb-17: "17.5.1.063-orioledb"
14+
postgres17: "17.6.1.042"
15+
postgres15: "15.14.1.042"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.19.0

nix/ext/pg_tle.nix

Lines changed: 92 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,111 @@
11
{
22
lib,
33
stdenv,
4+
buildEnv,
45
fetchFromGitHub,
56
postgresql,
67
flex,
78
openssl,
89
libkrb5,
910
}:
10-
11-
stdenv.mkDerivation rec {
11+
let
1212
pname = "pg_tle";
13-
version = "1.4.0";
13+
build =
14+
version: hash:
15+
stdenv.mkDerivation rec {
16+
inherit pname version;
1417

15-
nativeBuildInputs = [ flex ];
16-
buildInputs = [
17-
openssl
18-
postgresql
19-
libkrb5
20-
];
18+
nativeBuildInputs = [ flex ];
19+
buildInputs = [
20+
openssl
21+
postgresql
22+
libkrb5
23+
];
2124

22-
src = fetchFromGitHub {
23-
owner = "aws";
24-
repo = pname;
25-
rev = "refs/tags/v${version}";
26-
hash = "sha256-crxj5R9jblIv0h8lpqddAoYe2UqgUlnvbOajKTzVces=";
27-
};
25+
src = fetchFromGitHub {
26+
owner = "aws";
27+
repo = pname;
28+
rev = "refs/tags/v${version}";
29+
inherit hash;
30+
};
31+
32+
makeFlags = [ "FLEX=flex" ];
33+
34+
installPhase = ''
2835
29-
makeFlags = [ "FLEX=flex" ];
36+
mkdir -p $out/{lib,share/postgresql/extension}
3037
31-
installPhase = ''
32-
mkdir -p $out/{lib,share/postgresql/extension}
38+
mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
3339
34-
cp *${postgresql.dlSuffix} $out/lib
35-
cp *.sql $out/share/postgresql/extension
36-
cp *.control $out/share/postgresql/extension
40+
create_sql_files() {
41+
if test -f ${pname}--${version}.sql; then
42+
cp ${pname}--${version}.sql $out/share/postgresql/extension
43+
fi
44+
echo "Creating SQL files for previous versions..."
45+
if [[ "${version}" == "${latestVersion}" ]]; then
46+
cp *.sql $out/share/postgresql/extension
47+
fi
48+
}
49+
50+
create_control_files() {
51+
sed -e "/^default_version =/d" \
52+
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \
53+
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
54+
55+
if [[ "${version}" == "${latestVersion}" ]]; then
56+
{
57+
echo "default_version = '${latestVersion}'"
58+
cat $out/share/postgresql/extension/${pname}--${latestVersion}.control
59+
} > $out/share/postgresql/extension/${pname}.control
60+
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
61+
fi
62+
}
63+
64+
create_sql_files
65+
create_control_files
66+
'';
67+
68+
meta = with lib; {
69+
description = "Framework for 'Trusted Language Extensions' in PostgreSQL";
70+
homepage = "https://github.com/aws/${pname}";
71+
license = licenses.postgresql;
72+
inherit (postgresql.meta) platforms;
73+
};
74+
};
75+
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
76+
supportedVersions = lib.filterAttrs (
77+
_: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql
78+
) allVersions;
79+
versions = lib.naturalSort (lib.attrNames supportedVersions);
80+
latestVersion = lib.last versions;
81+
numberOfVersions = builtins.length versions;
82+
packages = builtins.attrValues (
83+
lib.mapAttrs (name: value: build name value.hash) supportedVersions
84+
);
85+
in
86+
buildEnv {
87+
name = pname;
88+
paths = packages;
89+
pathsToLink = [
90+
"/lib"
91+
"/share/postgresql/extension"
92+
];
93+
postBuild = ''
94+
# checks
95+
(set -x
96+
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
97+
toString (numberOfVersions + 1)
98+
}"
99+
)
37100
'';
38101

39-
meta = with lib; {
40-
description = "Framework for 'Trusted Language Extensions' in PostgreSQL";
41-
homepage = "https://github.com/aws/${pname}";
42-
platforms = postgresql.meta.platforms;
43-
license = licenses.postgresql;
102+
passthru = {
103+
inherit versions numberOfVersions;
104+
pname = "${pname}-all";
105+
defaultSettings = {
106+
shared_preload_libraries = [ "pg_tle" ];
107+
};
108+
version =
109+
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
44110
};
45111
}

nix/ext/tests/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ builtins.listToAttrs (
222222
"pg_jsonschema"
223223
"pg_net"
224224
"pgaudit"
225+
"pg_tle"
225226
"vector"
226227
"wrappers"
227228
]

nix/ext/versions.json

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,24 @@
681681
"rust": "1.87.0"
682682
}
683683
},
684+
"pg_hashids": {
685+
"1.2.1": {
686+
"postgresql": [
687+
"15",
688+
"17"
689+
],
690+
"revision": "v1.2.1",
691+
"hash": "sha256-2yQ0JrhwZF9dGEIydOviDpQ+3ZhJ8T16dQt6KIirAJ0="
692+
},
693+
"1.3.0-cd0e1b31d52b394a0df64079406a14a4f7387cd6": {
694+
"postgresql": [
695+
"15",
696+
"17"
697+
],
698+
"revision": "cd0e1b31d52b394a0df64079406a14a4f7387cd6",
699+
"hash": "sha256-Nmb7XLqQflYZfqj0yrewfb1Hl5YgEB5wfjBunPwIuOU="
700+
}
701+
},
684702
"pg_repack": {
685703
"1.4.8": {
686704
"postgresql": [
@@ -711,22 +729,33 @@
711729
"hash": "sha256-wfjiLkx+S3zVrAynisX1GdazueVJ3EOwQEPcgUQt7eA="
712730
}
713731
},
714-
"pg_hashids": {
715-
"1.2.1": {
732+
"pg_tle": {
733+
"1.0.1": {
734+
"postgresql": [
735+
"15"
736+
],
737+
"hash": "sha256-yAe37nIgObjs0kZY1A0QBGMP/s45sC1HVRwxVRaXwXs="
738+
},
739+
"1.0.4": {
716740
"postgresql": [
717741
"15",
718742
"17"
719743
],
720-
"revision": "v1.2.1",
721-
"hash": "sha256-2yQ0JrhwZF9dGEIydOviDpQ+3ZhJ8T16dQt6KIirAJ0="
744+
"hash": "sha256-W/7pLy/27VatCdzUh1NZ4K2FRMD1erfHiFV2eY2x2W0="
722745
},
723-
"1.3.0-cd0e1b31d52b394a0df64079406a14a4f7387cd6": {
746+
"1.3.0": {
724747
"postgresql": [
725748
"15",
726749
"17"
727750
],
728-
"revision": "cd0e1b31d52b394a0df64079406a14a4f7387cd6",
729-
"hash": "sha256-Nmb7XLqQflYZfqj0yrewfb1Hl5YgEB5wfjBunPwIuOU="
751+
"hash": "sha256-Q4D4+eYPBONd8IKlDVfQa8wI4PJyKHkMPPqONqEWFLE="
752+
},
753+
"1.4.0": {
754+
"postgresql": [
755+
"15",
756+
"17"
757+
],
758+
"hash": "sha256-crxj5R9jblIv0h8lpqddAoYe2UqgUlnvbOajKTzVces="
730759
}
731760
}
732761
}

0 commit comments

Comments
 (0)