Skip to content
51 changes: 48 additions & 3 deletions nix/ext/pg_graphql/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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/"
Expand Down Expand Up @@ -120,8 +120,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;
Expand All @@ -135,10 +136,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;
};
Comment on lines +163 to +168
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in meta description.

"PostreSQL" should be "PostgreSQL".

Suggested fix
       meta = with lib; {
-        description = "GraphQL support for PostreSQL";
+        description = "GraphQL support for PostgreSQL";
         homepage = "https://github.com/supabase/${pname}";
         license = licenses.postgresql;
         inherit (postgresql.meta) platforms;
       };
🤖 Prompt for AI Agents
In `@nix/ext/pg_graphql/default.nix` around lines 156 - 161, Fix the typo in the
package metadata by updating the meta.description value in the meta attribute
set (symbol: meta and key: description) to spell "PostgreSQL" correctly instead
of "PostreSQL"; locate the description string in the meta block (the description
= "GraphQL support for PostreSQL"; line) and change it to "GraphQL support for
PostgreSQL".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny typo, I suggest we fix it in another PR:

postgres on git develop
> rg Postre
README.md
201:| [pg_graphql](https://github.com/supabase/pg_graphql/archive/v1.5.11.tar.gz) | [1.5.11](https://github.com/supabase/pg_graphql/archive/v1.5.11.tar.gz) | GraphQL support for PostreSQL |
235:| [pg_graphql](https://github.com/supabase/pg_graphql/archive/v1.5.11.tar.gz) | [1.5.11](https://github.com/supabase/pg_graphql/archive/v1.5.11.tar.gz) | GraphQL support for PostreSQL |
268:| [pg_graphql](https://github.com/supabase/pg_graphql/archive/v1.5.11.tar.gz) | [1.5.11](https://github.com/supabase/pg_graphql/archive/v1.5.11.tar.gz) | GraphQL support for PostreSQL |

nix/ext/wrappers/default.nix
161:          description = "Various Foreign Data Wrappers (FDWs) for PostreSQL";

nix/ext/pg_graphql/default.nix
99:          description = "GraphQL support for PostreSQL";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yvan-sraka, sounds good! That makes sense to address the typo across all files in a dedicated PR since it appears in multiple places.

Would you like me to create a GitHub issue to track this typo fix? I can open one that lists all 5 occurrences across the codebase (README.md, nix/ext/wrappers/default.nix, and nix/ext/pg_graphql/default.nix) to make it easier to address them all at once.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can open a new PR that fix it, that would be even better ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yvan-sraka, I'll create a PR to fix the typo across all files! Let me plan those changes.

Task: Fix typo "PostreSQL" → "PostgreSQL" across codebase

  • Fix 3 occurrences in README.md
  • Fix 1 occurrence in nix/ext/wrappers/default.nix
  • Fix 1 occurrence in nix/ext/pg_graphql/default.nix
  • Create PR with title "fix: correct typo PostreSQL → PostgreSQL"

💡 For code changes across multiple files, use @coderabbitai plan in an issue comment

};
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;
pathsToLink = [
"/lib"
"/share/postgresql/extension"
Expand Down
20 changes: 11 additions & 9 deletions nix/ext/pg_jsonschema/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,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
Expand All @@ -93,11 +93,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}

Expand Down Expand Up @@ -127,8 +122,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;
Expand All @@ -142,6 +138,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;
Expand All @@ -158,6 +156,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
Comment on lines +159 to +161
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# First, check if versions.json exists and examine it
echo "=== Checking versions.json ==="
if [ -f "nix/ext/versions.json" ]; then
    head -50 nix/ext/versions.json
else
    find . -name "versions.json" -type f 2>/dev/null | head -5
fi

Repository: supabase/postgres

Length of output: 1070


🏁 Script executed:

#!/bin/bash
set -euo pipefail
pg_version="${1:-17}"

python - "$pg_version" <<'PY'
import json, sys

pg = sys.argv[1]
with open("nix/ext/versions.json") as f:
    data = json.load(f)["pg_jsonschema"]

def vkey(v):
    return tuple(int(x) for x in v.split("."))

supported = sorted([v for v, m in data.items() if pg in m["postgresql"]], key=vkey)
unsupported = sorted([v for v, m in data.items() if pg not in m["postgresql"]], key=vkey)

print("pg_version:", pg)
print("supported:", supported)
print("unsupported:", unsupported)
print("oldest_supported:", supported[0] if supported else None)
print("unsupported_newer_than_oldest_supported:", [v for v in unsupported if supported and vkey(v) > vkey(supported[0])])
PY

Repository: supabase/postgres

Length of output: 214


🏁 Script executed:

#!/bin/bash
# Examine the default.nix file around lines 154-156
echo "=== Checking nix/ext/pg_jsonschema/default.nix ==="
if [ -f "nix/ext/pg_jsonschema/default.nix" ]; then
    sed -n '140,170p' nix/ext/pg_jsonschema/default.nix | cat -n
else
    find . -name "default.nix" -type f 2>/dev/null | grep pg_jsonschema | head -1
fi

Repository: supabase/postgres

Length of output: 1355


🏁 Script executed:

#!/bin/bash
# Get more context from default.nix
echo "=== Full context of pg_jsonschema/default.nix ==="
wc -l nix/ext/pg_jsonschema/default.nix
echo ""
echo "=== Looking for versions and unsupportedVersions definitions ==="
rg -n "versions\s*=" nix/ext/pg_jsonschema/default.nix | head -10
rg -n "unsupportedVersions\s*=" nix/ext/pg_jsonschema/default.nix | head -10

Repository: supabase/postgres

Length of output: 350


🏁 Script executed:

#!/bin/bash
# Show the entire file to understand context
cat nix/ext/pg_jsonschema/default.nix

Repository: supabase/postgres

Length of output: 6149


🏁 Script executed:

#!/bin/bash
# Check pg_graphql for comparison as mentioned in review
echo "=== Checking pg_graphql default.nix for comparison ==="
if [ -f "nix/ext/pg_graphql/default.nix" ]; then
    # Look for similar version handling
    rg -n -C 3 "unsupportedVersions|lib.head" nix/ext/pg_graphql/default.nix | head -30
fi

Repository: supabase/postgres

Length of output: 557


Code assumes unsupported versions are always older than the oldest supported version.

Currently this is true (for PG 17: unsupported are 0.1.0–0.3.1, oldest supported is 0.3.3), but the code makes a fragile assumption. If future versions break this invariant, copying ${lib.head versions}.sql to newer unsupported versions would use incorrect schema. Consider either:

  • Adding a runtime assertion that no unsupported version is newer than oldest supported, or
  • Following pg_graphql's approach and building SQL files for unsupported versions

If this is strictly for pg_upgrade compatibility with older schemas, the current approach is acceptable but should be documented.

🤖 Prompt for AI Agents
In `@nix/ext/pg_jsonschema/default.nix` around lines 154 - 156, The loop that
copies SQL for unsupportedVersions assumes every unsupported version is older
than lib.head versions (oldest supported) which is fragile; update the logic in
the for loop handling unsupportedVersions to either (A) assert at runtime that
every v in unsupportedVersions is <= lib.head versions (e.g. fail early if any
unsupported version is newer than lib.head versions) or (B) generate/build
proper SQL fixtures for each unsupported version instead of copying ${lib.head
versions}.sql; locate the loop using the symbols unsupportedVersions, versions,
lib.head and pname and implement one of these fixes and include a clear error
message if you choose the assertion approach.


create_sql_files() {
PREVIOUS_VERSION=""
while IFS= read -r i; do
Expand Down
20 changes: 11 additions & 9 deletions nix/ext/pg_stat_monitor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ let
) allVersions;

# Derived version information
versions = lib.naturalSort (lib.attrNames supportedVersions);
allVersionsList = lib.naturalSort (lib.attrNames supportedVersions);
versions = builtins.filter (v: (allVersions.${v}.pgUpgradeCompatible or true)) allVersionsList;
latestVersion = lib.last versions;
versionsToUse =
if latestOnly then
{ "${latestVersion}" = supportedVersions.${latestVersion}; }
else
supportedVersions;
versionsBuilt = if latestOnly then [ latestVersion ] else versions;
numberOfVersionsBuilt = builtins.length versionsBuilt;

# Filter to only build pg_upgrade compatible versions
pgUpgradeCompatibleVersions = lib.filterAttrs (
name: _: allVersions.${name}.pgUpgradeCompatible or true
) supportedVersions;
packages = builtins.attrValues (
lib.mapAttrs (name: value: build name value.hash value.revision) versionsToUse
lib.mapAttrs (name: value: build name value.hash value.revision) pgUpgradeCompatibleVersions
);

versionsBuilt = if latestOnly then [ latestVersion ] else versions;
numberOfVersionsBuilt = builtins.length versionsBuilt;

# Build function for individual versions
build =
version: hash: revision:
Expand Down
53 changes: 46 additions & 7 deletions nix/ext/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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
Expand All @@ -127,8 +129,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
""
}
Expand Down Expand Up @@ -218,7 +226,9 @@ let
}
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"
}
Expand Down Expand Up @@ -310,14 +320,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.succeed(
Expand All @@ -331,7 +344,34 @@ let
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)
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"):
# Test that all extension versions from postgresql 15 can be upgraded to postgresql 17 using pg_upgrade
for version in versions["15"]:
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
""
Expand Down Expand Up @@ -359,7 +399,6 @@ builtins.listToAttrs (
"pg_jsonschema"
"pg_net"
"pg_partman"
"pg_stat_monitor"
"pg_tle"
"pgaudit"
"pgtap"
Expand Down
2 changes: 1 addition & 1 deletion nix/ext/tests/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Loading
Loading