Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 77 additions & 15 deletions nix/ext/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ let
postgresqlWithExtension =
postgresql:
let
majorVersion = lib.versions.major postgresql.version;
majorVersion =
if postgresql.isOrioleDB then "orioledb-17" else lib.versions.major postgresql.version;
pkg = pkgs.buildEnv {
name = "postgresql-${majorVersion}-${pname}";
paths = [
postgresql
postgresql.lib
(installedExtension majorVersion)
];
paths =
[
postgresql
postgresql.lib
(installedExtension majorVersion)
]
++ lib.optional (postgresql.isOrioleDB
) self.packages.${pkgs.system}."psql_orioledb-17/exts/orioledb";
passthru = {
inherit (postgresql) version psqlSchema;
lib = pkg;
Expand All @@ -45,6 +49,7 @@ let
pkg;
psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17;
orioledb_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17;
in
self.inputs.nixpkgs.lib.nixos.runTest {
name = pname;
Expand All @@ -69,12 +74,6 @@ let
enable = true;
package = psql_15;
enableTCPIP = true;
initialScript = pkgs.writeText "init-postgres-with-password" ''
CREATE USER test WITH PASSWORD 'secret';
'';
authentication = ''
host test postgres samenet scram-sha-256
'';
settings = (installedExtension "15").defaultSettings or { };
};

Expand Down Expand Up @@ -118,20 +117,71 @@ let
requires = [ "postgresql-migrate.service" ];
};
};

specialisation.orioledb17.configuration = {
services.postgresql = {
package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17);
settings = lib.mkForce (
((installedExtension "17").defaultSettings or { })
// {
shared_preload_libraries = [
"orioledb"
] ++ (installedExtension "17").defaultSettings.shared_preload_libraries or [ ];
default_table_access_method = "orioledb";
}
);
initdbArgs = [
"--allow-group-access"
"--locale-provider=icu"
"--encoding=UTF-8"
"--icu-locale=en_US.UTF-8"
];
initialScript = pkgs.writeText "init-postgres-with-orioledb" ''
CREATE EXTENSION orioledb CASCADE;
'';
};

systemd.services.postgresql-migrate = {
# we don't support migrating from postgresql 17 to orioledb-17 so we just reinit the datadir
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
User = "postgres";
Group = "postgres";
StateDirectory = "postgresql";
WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}";
};
script =
let
newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17;
in
''
set -x
systemctl cat postgresql.service
rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}
'';
};

systemd.services.postgresql = {
after = [ "postgresql-migrate.service" ];
requires = [ "postgresql-migrate.service" ];
};
};
};
testScript =
{ nodes, ... }:
let
pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17";
orioledb17-configuration = "${nodes.server.system.build.toplevel}/specialisation/orioledb17";
in
''
from pathlib import Path
versions = {
"15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}],
"17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}],
"orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}],
}
extension_name = "${pname}"
pg17_configuration = "${pg17-configuration}"
ext_has_background_worker = ${
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
}
Expand Down Expand Up @@ -166,7 +216,7 @@ let

with subtest("switch to postgresql 17"):
server.succeed(
f"{pg17_configuration}/bin/switch-to-configuration test >&2"
"${pg17-configuration}/bin/switch-to-configuration test >&2"
)

with subtest("Check last version of the extension after postgresql upgrade"):
Expand All @@ -183,6 +233,19 @@ let

with subtest("Check pg_regress with postgresql 17 after installing the last version"):
test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name)

with subtest("switch to orioledb 17"):
server.succeed(
"${orioledb17-configuration}/bin/switch-to-configuration test >&2"
)
installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""")
assert "orioledb" in installed_extensions

with subtest("Check upgrade path with orioledb 17"):
test.check_upgrade_path("orioledb-17")

with subtest("Check pg_regress with orioledb 17 after installing the last version"):
test.check_pg_regress(Path("${orioledb_17}/lib/pgxs/src/test/regress/pg_regress"), "orioledb-17", pg_regress_test_name)
'';
};
in
Expand All @@ -200,7 +263,6 @@ builtins.listToAttrs (
})
[
"hypopg"
"index_advisor"
"pg_cron"
"pg_hashids"
"pg_graphql"
Expand Down
Loading