Skip to content
Merged
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
18 changes: 16 additions & 2 deletions nix/ext/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,26 @@ let
""
}

has_update_script = False
with subtest("switch to postgresql 17"):
server.succeed(
f"{pg17_configuration}/bin/switch-to-configuration test >&2"
)
server.wait_for_unit("postgresql.service")
has_update_script = server.succeed(
"test -f /var/lib/postgresql/update_extensions.sql && echo 'yes' || echo 'no'"
).strip() == "yes"
if has_update_script:
# Run the extension update script generated during the upgrade
test.run_sql_file("/var/lib/postgresql/update_extensions.sql")

with subtest("Check last version of the extension after postgresql upgrade"):
test.assert_version_matches(last_version)
if has_update_script:
# If there was an update script, the last version should be installed
test.assert_version_matches(versions["17"][-1])
else:
# Otherwise, the version should match the last version from postgresql 15
test.assert_version_matches(last_version)

${
if support_upgrade then
Expand Down Expand Up @@ -271,11 +284,12 @@ builtins.listToAttrs (
"pg_hashids"
"pg_jsonschema"
"pg_net"
"pg_partman"
"pg_repack"
"pg_stat_monitor"
"pg_tle"
"pgaudit"
"pg_partman"
"postgis"
"vector"
"wal2json"
"wrappers"
Expand Down
3 changes: 3 additions & 0 deletions nix/ext/tests/http.nix
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,6 @@ self.inputs.nixpkgs.lib.nixos.runTest {
check_upgrade_path("17")
'';
}
# We don't use the generic test for this extension because:
# http is not using semver versioning scheme, so we need to adapt the version checks
# otherwise the test fails with ERROR: extension "http" has no installation script nor update path for version "1.5.0"
69 changes: 39 additions & 30 deletions nix/ext/tests/postgis.nix → nix/ext/tests/pg_repack.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ self, pkgs }:
let
pname = "postgis";
pname = "pg_repack";
inherit (pkgs) lib;
installedExtension =
postgresMajorVersion:
Expand Down Expand Up @@ -64,8 +64,25 @@ self.inputs.nixpkgs.lib.nixos.runTest {
services.postgresql = {
enable = true;
package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15;
enableTCPIP = true;
authentication = ''
local all postgres peer map=postgres
local all all peer map=root
'';
identMap = ''
root root supabase_admin
postgres postgres postgres
'';
ensureUsers = [
{
name = "supabase_admin";
ensureClauses.superuser = true;
}
];
};

networking.firewall.allowedTCPPorts = [ config.services.postgresql.settings.port ];

specialisation.postgresql17.configuration = {
services.postgresql = {
package = lib.mkForce (
Expand Down Expand Up @@ -117,52 +134,44 @@ self.inputs.nixpkgs.lib.nixos.runTest {
pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17";
in
''
from pathlib import Path
versions = {
"15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}],
"17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}],
}
extension_name = "${pname}"
support_upgrade = False
pg17_configuration = "${pg17-configuration}"
sql_test_directory = Path("${../../tests}")

def run_sql(query):
return server.succeed(f"""sudo -u postgres psql -t -A -F\",\" -c \"{query}\" """).strip()

def check_upgrade_path(pg_version):
with subtest("Check ${pname} upgrade path"):
firstVersion = versions[pg_version][0]
server.succeed("sudo -u postgres psql -c 'DROP EXTENSION IF EXISTS ${pname};'")
run_sql(f"""CREATE EXTENSION ${pname} WITH VERSION '{firstVersion}' CASCADE;""")
installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${pname}';""")
assert installed_version == firstVersion, f"Expected ${pname} version {firstVersion}, but found {installed_version}"
for version in versions[pg_version][1:]:
run_sql(f"""ALTER EXTENSION ${pname} UPDATE TO '{version}';""")
installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${pname}';""")
assert installed_version == version, f"Expected ${pname} version {version}, but found {installed_version}"
${builtins.readFile ./lib.py}

start_all()

server.wait_for_unit("multi-user.target")
server.wait_for_unit("postgresql.service")

check_upgrade_path("15")
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade)

with subtest("Check upgrade path with postgresql 15"):
test.check_upgrade_path("15")

with subtest("Check ${pname} latest extension version"):
server.succeed("sudo -u postgres psql -c 'DROP EXTENSION ${pname};'")
server.succeed("sudo -u postgres psql -c 'CREATE EXTENSION ${pname} CASCADE;'")
installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension where extname = '${pname}';""")
latestVersion = versions["15"][-1]
majMinVersion = ".".join(latestVersion.split('.')[:1])
assert f"${pname},{majMinVersion}" in installed_extensions, f"Expected ${pname} version {latestVersion}, but found {installed_extensions}"
last_version = None
with subtest("Check the install of the last version of the extension"):
last_version = test.check_install_last_version("15")

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

with subtest("Check ${pname} latest extension version after upgrade"):
installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension;""")
latestVersion = versions["17"][-1]
majMinVersion = ".".join(latestVersion.split('.')[:1])
assert f"${pname},{majMinVersion}" in installed_extensions
with subtest("Check last version of the extension after upgrade"):
test.assert_version_matches(last_version)

check_upgrade_path("17")
with subtest("Check upgrade path with postgresql 17"):
test.check_upgrade_path("17")
'';
}
# We don't use the generic test for this extension because:
# pg_repack does not support upgrade as the extension doesn't provide the upgrade SQL scripts
# and fails with ERROR: extension "pg_repack" has no update path from version "1.4.8" to version "1.5.0"
1 change: 1 addition & 0 deletions nix/ext/tests/pgrouting.nix
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,4 @@ self.inputs.nixpkgs.lib.nixos.runTest {
check_upgrade_path("orioledb-17")
'';
}
# We don't use the generic test for this extension because: it requires postgis to be installed as well.
Loading