Skip to content

Commit 3e621f8

Browse files
committed
feat: test pg_upgrade compatibility with older extension versions
Add test to verify that all extension versions from PostgreSQL 15 can successfully upgrade to PostgreSQL 17 using pg_upgrade. The test now validates: - Each PG 15 extension version can be upgraded to PG 17 - Extension update scripts are properly generated during upgrade - Version handling works correctly with and without update scripts - Final extension versions match expected values after upgrade
1 parent b6b2588 commit 3e621f8

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

nix/ext/tests/default.nix

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@ let
129129
};
130130
testScript =
131131
{ nodes, ... }:
132-
let
133-
pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17";
134-
in
135132
''
136133
from pathlib import Path
137134
versions = {
138135
"15": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "15"))}],
139136
"17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}],
140137
}
141138
extension_name = "${pname}"
142-
pg17_configuration = "${pg17-configuration}"
139+
system = "${nodes.server.system.build.toplevel}"
140+
pg15_configuration = system
141+
pg17_configuration = f"{system}/specialisation/postgresql17"
143142
ext_has_background_worker = ${
144143
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
145144
}
@@ -191,6 +190,34 @@ let
191190
192191
with subtest("Check pg_regress with postgresql 17 after installing the last version"):
193192
test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name)
193+
194+
with subtest("Test pg_upgrade from postgresql 15 to 17 with older extension version"):
195+
# Test that all extension versions from postgresql 15 can be upgraded to postgresql 17 using pg_upgrade
196+
for version in versions["15"]:
197+
server.systemctl("stop postgresql.service")
198+
server.succeed("rm -fr /var/lib/postgresql/update_extensions.sql /var/lib/postgresql/17")
199+
server.succeed(
200+
f"{pg15_configuration}/bin/switch-to-configuration test >&2"
201+
)
202+
test.drop_extension()
203+
test.install_extension(version)
204+
server.succeed(
205+
f"{pg17_configuration}/bin/switch-to-configuration test >&2"
206+
)
207+
has_update_script = server.succeed(
208+
"test -f /var/lib/postgresql/update_extensions.sql && echo 'yes' || echo 'no'"
209+
).strip() == "yes"
210+
if has_update_script:
211+
# Run the extension update script generated during the upgrade
212+
test.run_sql_file("/var/lib/postgresql/update_extensions.sql")
213+
if has_update_script:
214+
# If there was an update script, the last version should be installed
215+
test.assert_version_matches(versions["17"][-1])
216+
else:
217+
# Otherwise, the version should match the version from postgresql 15
218+
test.assert_version_matches(version)
219+
220+
test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name)
194221
'';
195222
};
196223
in

0 commit comments

Comments
 (0)