From af79a012f2dd855aca87c685f9d0228f2af51917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Tue, 24 Nov 2026 01:29:27 +0200 Subject: [PATCH 1/3] test(ext): pg_upgrade 15 to 17 with every old extension version Loop the extension tests over each PG15 extension version, upgrade to PG17 with pg_upgrade, and check the resulting version. Ship SQL-only files for PG15-only pg_graphql and pg_jsonschema versions so PG17 can load them. Skip versions flagged pgUpgradeCompatible: false. Based on #1897. Co-Authored-By: Claude Sonnet 5.5 --- nix/ext/pg_graphql/default.nix | 51 ++++++++++++++++++++++++++-- nix/ext/pg_jsonschema/default.nix | 20 ++++++----- nix/ext/tests/default.nix | 56 +++++++++++++++++++++++++++---- nix/ext/tests/lib.py | 2 +- nix/ext/versions.json | 3 +- 5 files changed, 112 insertions(+), 20 deletions(-) diff --git a/nix/ext/pg_graphql/default.nix b/nix/ext/pg_graphql/default.nix index 6de270c3d6..ed23320c1e 100644 --- a/nix/ext/pg_graphql/default.nix +++ b/nix/ext/pg_graphql/default.nix @@ -74,7 +74,7 @@ let preCheck = '' export PGRX_HOME="$(mktemp -d)" - export PG_VERSION="${lib.versions.major postgresql.version}" + export PG_VERSION="${pgVersion}" export NIX_PGLIBDIR="$PGRX_HOME/$PG_VERSION/lib" export PATH="$PGRX_HOME/$PG_VERSION/bin:$PATH" ${lib.getExe rsync} --chmod=ugo+w -a ${postgresql}/ ${postgresql.lib}/ "$PGRX_HOME/$PG_VERSION/" @@ -114,8 +114,9 @@ let } ); allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).pg_graphql; + pgVersion = lib.versions.major postgresql.version; supportedVersions = lib.filterAttrs ( - _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql + _: value: builtins.elem pgVersion value.postgresql ) allVersions; versions = lib.naturalSort (lib.attrNames supportedVersions); latestVersion = lib.last versions; @@ -129,10 +130,54 @@ let packages = builtins.attrValues ( lib.mapAttrs (name: value: build name value.hash value.rust value.pgrx) versionsToUse ); + buildUnsupported = + # Build SQL-only packages for unsupported versions needed by pg_upgrade. + # When upgrading PostgreSQL, pg_upgrade requires old extension versions to exist + # even if they can't compile against the new PostgreSQL version. + version: hash: _rustVersion: _pgrxVersion: + stdenv.mkDerivation { + inherit pname version; + src = fetchFromGitHub { + owner = "supabase"; + repo = pname; + rev = "v${version}"; + inherit hash; + }; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/share/postgresql/extension + for file in $src/sql/*.sql; do + filename=$(basename "$file") + if [[ "$filename" != "load_sql_config.sql" && "$filename" != "load_sql_context.sql" ]]; then + cat "$file" + echo ";" + fi + done > $out/share/postgresql/extension/${pname}--${version}.sql + ''; + meta = with lib; { + description = "GraphQL support for PostreSQL"; + homepage = "https://github.com/supabase/${pname}"; + license = licenses.postgresql; + inherit (postgresql.meta) platforms; + }; + }; + unsupportedVersions = lib.filterAttrs ( + _: value: !builtins.elem pgVersion value.postgresql + ) allVersions; + unsupportedPackages = + if pgVersion == "15" then + [ ] + else + # Include SQL-only packages for PG15 extension versions incompatible with current PG + builtins.attrValues ( + lib.mapAttrs ( + name: value: buildUnsupported name value.hash value.rust value.pgrx + ) unsupportedVersions + ); in (buildEnv { name = pname; - paths = packages; + paths = packages ++ unsupportedPackages; nativeBuildInputs = [ makeWrapper ]; pathsToLink = [ "/lib" diff --git a/nix/ext/pg_jsonschema/default.nix b/nix/ext/pg_jsonschema/default.nix index 8e5916e0b3..add2c37650 100644 --- a/nix/ext/pg_jsonschema/default.nix +++ b/nix/ext/pg_jsonschema/default.nix @@ -78,9 +78,9 @@ let preCheck = '' export PGRX_HOME=$(mktemp -d) - export NIX_PGLIBDIR=$PGRX_HOME/${lib.versions.major postgresql.version}/lib - ${lib.getExe pkgs.rsync} --chmod=ugo+w -a ${postgresql}/ ${postgresql.lib}/ $PGRX_HOME/${lib.versions.major postgresql.version}/ - cargo pgrx init --pg${lib.versions.major postgresql.version} $PGRX_HOME/${lib.versions.major postgresql.version}/bin/pg_config + export NIX_PGLIBDIR=$PGRX_HOME/${pgVersion}/lib + ${lib.getExe pkgs.rsync} --chmod=ugo+w -a ${postgresql}/ ${postgresql.lib}/ $PGRX_HOME/${pgVersion}/ + cargo pgrx init --pg${pgVersion} $PGRX_HOME/${pgVersion}/bin/pg_config ''; # Tests are disabled for specific versions because pgrx tests require @@ -95,11 +95,6 @@ let "0.3.3" ]); - preBuild = '' - echo "Processing git tags..." - echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt - ''; - postInstall = '' mv $out/lib/${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} @@ -129,8 +124,9 @@ let }; }; allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).pg_jsonschema; + pgVersion = lib.versions.major postgresql.version; supportedVersions = lib.filterAttrs ( - _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql + _: value: builtins.elem pgVersion value.postgresql ) allVersions; versions = lib.naturalSort (lib.attrNames supportedVersions); latestVersion = lib.last versions; @@ -144,6 +140,8 @@ let ); versionsBuilt = if latestOnly then [ latestVersion ] else versions; numberOfVersionsBuilt = builtins.length versionsBuilt; + unsupportedVersionsItems = lib.filterAttrs (_: value: value.postgresql == [ "15" ]) allVersions; + unsupportedVersions = if pgVersion == "17" then lib.attrNames unsupportedVersionsItems else [ ]; in (pkgs.buildEnv { name = pname; @@ -161,6 +159,10 @@ in }" ) + for v in ${lib.concatStringsSep " " unsupportedVersions}; do + cp $out/share/postgresql/extension/${pname}--${lib.head versions}.sql $out/share/postgresql/extension/${pname}--$v.sql + done + create_sql_files() { PREVIOUS_VERSION="" while IFS= read -r i; do diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index 141e9bab0f..081fe31203 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -300,6 +300,8 @@ let newPostgresql = psql_17; oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; + oldSettings = (installedExtension "15").defaultSettings or { }; + newSettings = (installedExtension "17").defaultSettings or { }; in '' if [[ ! -d ${newDataDir} ]]; then @@ -308,8 +310,14 @@ let ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" \ ${ - if config.services.postgresql.settings.shared_preload_libraries != null then - " --old-options='-c shared_preload_libraries=${config.services.postgresql.settings.shared_preload_libraries}' --new-options='-c shared_preload_libraries=${config.services.postgresql.settings.shared_preload_libraries}'" + let + oldLibs = oldSettings.shared_preload_libraries or ""; + newLibs = newSettings.shared_preload_libraries or ""; + oldLibsStr = if builtins.isList oldLibs then lib.concatStringsSep "," oldLibs else oldLibs; + newLibsStr = if builtins.isList newLibs then lib.concatStringsSep "," newLibs else newLibs; + in + if oldSettings ? shared_preload_libraries || newSettings ? shared_preload_libraries then + " --old-options='-c shared_preload_libraries=${oldLibsStr}' --new-options='-c shared_preload_libraries=${newLibsStr}'" else "" } @@ -392,6 +400,10 @@ let let pg17-configuration = "${nodes.server.system.build.toplevel}/specialisation/postgresql17"; orioledb17-configuration = "${nodes.server.system.build.toplevel}/specialisation/orioledb17"; + extVersionData = (builtins.fromJSON (builtins.readFile ../versions.json)).${pname} or { }; + pgUpgradeVersions = builtins.filter (v: (extVersionData.${v}.pgUpgradeCompatible or true)) ( + versions "15" + ); in '' from pathlib import Path @@ -401,9 +413,12 @@ let "17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}], "orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}], } + pg_upgrade_versions = [${lib.concatStringsSep ", " (map (s: ''"${s}"'') pgUpgradeVersions)}] extension_name = "${pname}" support_upgrade = ${if support_upgrade then "True" else "False"} - pg17_configuration = "${pg17-configuration}" + system = "${nodes.server.system.build.toplevel}" + pg15_configuration = system + pg17_configuration = f"{system}/specialisation/postgresql17" ext_has_background_worker = ${ if support_upgrade && (installedExtension "15") ? hasBackgroundWorker then "True" else "False" } @@ -504,14 +519,17 @@ let ${ if run_pg_regress then '' + psql_17 = "${psql_17}" + orioledb_17 = "${orioledb_17}" + with subtest("Check pg_regress with postgresql 17 after extension upgrade"): - test.check_pg_regress(Path("${psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) + test.check_pg_regress(Path(f"{psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) with subtest("Check the install of the last version of the extension"): test.check_install_last_version("17") 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) + test.check_pg_regress(Path(f"{psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) with subtest("switch to orioledb 17"): server.execute( @@ -529,7 +547,33 @@ let test.check_legacy_versions_upgrade_to_latest("orioledb-17", legacy_versions) 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) + test.check_pg_regress(Path(f"{orioledb_17}/lib/pgxs/src/test/regress/pg_regress"), "orioledb-17", pg_regress_test_name) + + with subtest("Test pg_upgrade from postgresql 15 to 17 with older extension version"): + for version in pg_upgrade_versions: + server.systemctl("stop postgresql.service") + server.succeed("rm -fr /var/lib/postgresql/update_extensions.sql /var/lib/postgresql/17") + server.succeed( + f"{pg15_configuration}/bin/switch-to-configuration test >&2" + ) + test.drop_extension() + test.install_extension(version) + server.succeed( + f"{pg17_configuration}/bin/switch-to-configuration test >&2" + ) + 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") + # 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 version from postgresql 15 + test.assert_version_matches(version) + + test.check_pg_regress(Path(f"{psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) '' else "" diff --git a/nix/ext/tests/lib.py b/nix/ext/tests/lib.py index b2cdbb7bc4..d1ba7ab59f 100644 --- a/nix/ext/tests/lib.py +++ b/nix/ext/tests/lib.py @@ -55,7 +55,7 @@ def run_sql_file(self, file: str) -> str: ).strip() def drop_extension(self): - self.run_sql(f"DROP EXTENSION IF EXISTS {self.extension_name};") + self.run_sql(f"DROP EXTENSION IF EXISTS {self.extension_name} CASCADE;") def install_extension(self, version: str): if self.schema != "public": diff --git a/nix/ext/versions.json b/nix/ext/versions.json index da9ce3a1ed..d83fc00a97 100644 --- a/nix/ext/versions.json +++ b/nix/ext/versions.json @@ -590,7 +590,8 @@ "1.0": { "postgresql": ["15"], "revision": "1.0.1", - "hash": "sha256-sQEpIknAFOmvNTX2G23X4BvMdy3Ms7sXx7hLZt8jyUk=" + "hash": "sha256-sQEpIknAFOmvNTX2G23X4BvMdy3Ms7sXx7hLZt8jyUk=", + "pgUpgradeCompatible": false }, "2.1": { "postgresql": ["15", "17"], From 470f3d4330a0fb08745d0c0b4c612edc9a6901cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Tue, 24 Nov 2026 14:36:12 +0200 Subject: [PATCH 2/3] fix(ext): run post-upgrade pg_regress only on the latest version Co-Authored-By: Claude Sonnet 5.5 --- nix/ext/tests/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index 081fe31203..717848a847 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -573,7 +573,8 @@ let # Otherwise, the version should match the version from postgresql 15 test.assert_version_matches(version) - test.check_pg_regress(Path(f"{psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) + if has_update_script or version == versions["17"][-1]: + test.check_pg_regress(Path(f"{psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) '' else "" From e08aa6ab9f7004cf500b77931c38288721f236e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Boros?= Date: Thu, 26 Nov 2026 04:57:31 +0200 Subject: [PATCH 3/3] test(ext): probe pg_stat_monitor query after pg_upgrade Co-Authored-By: Claude Sonnet 5.5 --- nix/ext/tests/default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index 717848a847..a100540130 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -573,7 +573,9 @@ let # Otherwise, the version should match the version from postgresql 15 test.assert_version_matches(version) - if has_update_script or version == versions["17"][-1]: + if extension_name == "pg_stat_monitor": + test.run_sql("SELECT * FROM pg_stat_monitor LIMIT 1;") + elif has_update_script or version == versions["17"][-1]: test.check_pg_regress(Path(f"{psql_17}/lib/pgxs/src/test/regress/pg_regress"), "17", pg_regress_test_name) '' else