1 # mostly copied from ./timescaledb.nix which was copied from ./postgresql.nix
2 # as it seemed unapproriate to test additional extensions for postgresql there.
4 { system ? builtins.currentSystem
6 , pkgs ? import ../.. { inherit system config; }
9 with import ../lib/testing-python.nix { inherit system pkgs; };
13 postgresql-versions = import ../../pkgs/servers/sql/postgresql pkgs;
14 # Test cases from https://docs.pgvecto.rs/use-cases/hybrid-search.html
15 test-sql = pkgs.writeText "postgresql-test" ''
16 CREATE EXTENSION vectors;
19 id bigserial PRIMARY KEY,
20 content text NOT NULL,
21 embedding vectors.vector(3) NOT NULL -- 3 dimensions
24 INSERT INTO items (content, embedding) VALUES
25 ('a fat cat sat on a mat and ate a fat rat', '[1, 2, 3]'),
26 ('a fat dog sat on a mat and ate a fat rat', '[4, 5, 6]'),
27 ('a thin cat sat on a mat and ate a thin rat', '[7, 8, 9]'),
28 ('a thin dog sat on a mat and ate a thin rat', '[10, 11, 12]');
30 make-postgresql-test = postgresql-name: postgresql-package: makeTest {
31 name = postgresql-name;
32 meta = with pkgs.lib.maintainers; {
33 maintainers = [ diogotcorreia ];
36 nodes.machine = { ... }:
38 services.postgresql = {
40 package = postgresql-package;
41 extraPlugins = ps: with ps; [
44 settings.shared_preload_libraries = "vectors";
49 def check_count(statement, lines):
50 return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
56 machine.wait_for_unit("postgresql")
58 with subtest("Postgresql with extension vectors is available just after unit start"):
59 machine.succeed(check_count("SELECT * FROM pg_available_extensions WHERE name = 'vectors' AND default_version = '${postgresql-package.pkgs.pgvecto-rs.version}';", 1))
61 machine.succeed("sudo -u postgres psql -f ${test-sql}")
63 machine.succeed(check_count("SELECT content, embedding FROM items WHERE to_tsvector('english', content) @@ 'cat & rat'::tsquery;", 2))
69 applicablePostgresqlVersions = filterAttrs (_: value: versionAtLeast value.version "14") postgresql-versions;
74 value = make-postgresql-test name package;
76 applicablePostgresqlVersions