1 # mostly copied from ./postgresql.nix as it seemed unapproriate to
2 # 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-sql = pkgs.writeText "postgresql-test" ''
15 CREATE EXTENSION timescaledb;
16 CREATE EXTENSION timescaledb_toolkit;
19 time TIMESTAMPTZ NOT NULL,
20 value DOUBLE PRECISION
23 SELECT create_hypertable('sth', 'time');
25 INSERT INTO sth (time, value) VALUES
26 ('2003-04-12 04:05:06 America/New_York', 1.0),
27 ('2003-04-12 04:05:07 America/New_York', 2.0),
28 ('2003-04-12 04:05:08 America/New_York', 3.0),
29 ('2003-04-12 04:05:09 America/New_York', 4.0),
30 ('2003-04-12 04:05:10 America/New_York', 5.0)
35 time_bucket('1 day'::interval, time) AS dt,
36 stats_agg(value) AS stats
38 GROUP BY time_bucket('1 day'::interval, time)
44 make-postgresql-test = postgresql-name: postgresql-package: makeTest {
45 name = postgresql-name;
46 meta = with pkgs.lib.maintainers; {
47 maintainers = [ typetetris ];
50 nodes.machine = { ... }:
52 services.postgresql = {
54 package = postgresql-package;
55 extraPlugins = ps: with ps; [
59 settings = { shared_preload_libraries = "timescaledb, timescaledb_toolkit"; };
64 def check_count(statement, lines):
65 return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format(
71 machine.wait_for_unit("postgresql")
73 with subtest("Postgresql with extensions timescaledb and timescaledb_toolkit is available just after unit start"):
75 "sudo -u postgres psql -f ${test-sql}"
78 machine.fail(check_count("SELECT * FROM sth;", 3))
79 machine.succeed(check_count("SELECT * FROM sth;", 5))
80 machine.fail(check_count("SELECT * FROM sth;", 4))
86 applicablePostgresqlVersions = filterAttrs (_: value: versionAtLeast value.version "14") postgresql-versions;
91 value = make-postgresql-test name package;
93 applicablePostgresqlVersions