Skip to content

Commit 07758cd

Browse files
jfrochesamrose
andauthored
feat: support multiple versions of the vector extension (#1750)
* feat: multiple versions for the vector extension Build multiple versions of the vector extension on different PostgreSQL versions. Add test for the extensions and their upgrade on PostgreSQL 15 and 17. * chore: add release suffix for testing * fix: rebase to develop * chore: bump version for release * chore: refactor to run default nixos test --------- Co-authored-by: Sam Rose <[email protected]>
1 parent 86fe049 commit 07758cd

File tree

4 files changed

+132
-25
lines changed

4 files changed

+132
-25
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.024-orioledb"
13-
postgres17: "17.6.1.003"
14-
postgres15: "15.14.1.003"
12+
postgresorioledb-17: "17.5.1.025-orioledb"
13+
postgres17: "17.6.1.004"
14+
postgres15: "15.14.1.004"
1515

1616
# Non Postgres Extensions
1717
pgbouncer_release: "1.19.0"

nix/ext/pgvector.nix

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,92 @@
11
{
2+
pkgs,
23
lib,
34
stdenv,
45
fetchFromGitHub,
56
postgresql,
67
}:
8+
let
9+
pname = "vector";
710

8-
stdenv.mkDerivation rec {
9-
pname = "pgvector";
10-
version = "0.8.0";
11+
# Load version configuration from external file
12+
allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname};
1113

12-
buildInputs = [ postgresql ];
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;
1318

14-
src = fetchFromGitHub {
15-
owner = "pgvector";
16-
repo = pname;
17-
rev = "refs/tags/v${version}";
18-
hash = "sha256-JsZV+I4eRMypXTjGmjCtMBXDVpqTIPHQa28ogXncE/Q=";
19-
};
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) supportedVersions
25+
);
26+
27+
# Build function for individual versions
28+
build =
29+
version: hash:
30+
stdenv.mkDerivation rec {
31+
inherit pname version;
32+
33+
buildInputs = [ postgresql ];
34+
35+
src = fetchFromGitHub {
36+
owner = "pgvector";
37+
repo = "pgvector";
38+
rev = "refs/tags/v${version}";
39+
inherit hash;
40+
};
41+
42+
installPhase = ''
43+
mkdir -p $out/{lib,share/postgresql/extension}
44+
45+
# Install shared library with version suffix
46+
mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
47+
48+
# Create version-specific control file
49+
sed -e "/^default_version =/d" \
50+
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \
51+
${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control
52+
53+
# Copy SQL file to install the specific version
54+
cp sql/${pname}.sql $out/share/postgresql/extension/${pname}--${version}.sql
55+
56+
# For the latest version, copy sql upgrade script, default control file and symlink
57+
if [[ "${version}" == "${latestVersion}" ]]; then
58+
cp sql/*.sql $out/share/postgresql/extension
59+
{
60+
echo "default_version = '${latestVersion}'"
61+
cat $out/share/postgresql/extension/${pname}--${latestVersion}.control
62+
} > $out/share/postgresql/extension/${pname}.control
63+
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
64+
fi
2065
21-
installPhase = ''
22-
mkdir -p $out/{lib,share/postgresql/extension}
66+
runHook postInstall
67+
'';
2368

24-
cp *${postgresql.dlSuffix} $out/lib
25-
cp sql/*.sql $out/share/postgresql/extension
26-
cp *.control $out/share/postgresql/extension
27-
'';
69+
meta = with lib; {
70+
description = "Open-source vector similarity search for Postgres";
71+
homepage = "https://github.com/${src.owner}/${src.repo}";
72+
maintainers = with maintainers; [ olirice ];
73+
platforms = postgresql.meta.platforms;
74+
license = licenses.postgresql;
75+
};
76+
};
77+
in
78+
pkgs.buildEnv {
79+
name = pname;
80+
paths = packages;
81+
pathsToLink = [
82+
"/lib"
83+
"/share/postgresql/extension"
84+
];
2885

29-
meta = with lib; {
30-
description = "Open-source vector similarity search for Postgres";
31-
homepage = "https://github.com/${src.owner}/${src.repo}";
32-
maintainers = with maintainers; [ olirice ];
33-
platforms = postgresql.meta.platforms;
34-
license = licenses.postgresql;
86+
passthru = {
87+
inherit versions numberOfVersions;
88+
pname = "${pname}-all";
89+
version =
90+
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);
3591
};
3692
}

nix/ext/tests/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ builtins.listToAttrs (
185185
"index_advisor"
186186
"pg_cron"
187187
"pg_net"
188+
"vector"
188189
"wrappers"
189190
]
190191
)

nix/ext/versions.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,55 @@
127127
],
128128
"hash": "sha256-Cpi2iASi1QJoED0Qs1dANqg/BNZTsz5S+pw8iYyW03Y="
129129
}
130+
},
131+
"vector": {
132+
"0.4.0": {
133+
"postgresql": [
134+
"15"
135+
],
136+
"hash": "sha256-bOckX7zvHhgJDDhoAm+VZVIeVIf2hG/3oWZWuTtnZPo="
137+
},
138+
"0.5.1": {
139+
"postgresql": [
140+
"15",
141+
"17"
142+
],
143+
"hash": "sha256-ZNzq+dATZn9LUgeOczsaadr5hwdbt9y/+sAOPIdr77U="
144+
},
145+
"0.6.0": {
146+
"postgresql": [
147+
"15",
148+
"17"
149+
],
150+
"hash": "sha256-hXm+k0BZ9xZP1Tnek14jPoKCPQkA5ovscu9IX2mW7Kc="
151+
},
152+
"0.6.2": {
153+
"postgresql": [
154+
"15",
155+
"17"
156+
],
157+
"hash": "sha256-r+TpFJg6WrMn0L2B7RpmSRvw3XxpHzMRtpFWDCzLvgs="
158+
},
159+
"0.7.0": {
160+
"postgresql": [
161+
"15",
162+
"17"
163+
],
164+
"hash": "sha256-vFn7sNphOYyig6Jl1HILMaC2t9strFQBQ8ywL8Ibx1M="
165+
},
166+
"0.7.4": {
167+
"postgresql": [
168+
"15",
169+
"17"
170+
],
171+
"hash": "sha256-qwPaguQUdDHV8q6GDneLq5MuhVroPizpbqt7f08gKJI="
172+
},
173+
"0.8.0": {
174+
"postgresql": [
175+
"15",
176+
"17"
177+
],
178+
"hash": "sha256-JsZV+I4eRMypXTjGmjCtMBXDVpqTIPHQa28ogXncE/Q="
179+
}
130180
}
131181
}

0 commit comments

Comments
 (0)