-
-
Notifications
You must be signed in to change notification settings - Fork 231
feat: support multiple versions of the supautils extension #1921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jfroche
wants to merge
2
commits into
develop
Choose a base branch
from
multi-version-ext/supautils
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,96 @@ | ||
| { | ||
| pkgs, | ||
| lib, | ||
| stdenv, | ||
| fetchFromGitHub, | ||
| postgresql, | ||
| }: | ||
|
|
||
| stdenv.mkDerivation rec { | ||
| let | ||
| pname = "supautils"; | ||
| name = pname; | ||
| version = "3.0.1"; | ||
| # Load version configuration from external file | ||
| allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname}; | ||
|
|
||
| buildInputs = [ postgresql ]; | ||
| # Filter versions compatible with current PostgreSQL version | ||
| supportedVersions = lib.filterAttrs ( | ||
| _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql | ||
| ) allVersions; | ||
|
|
||
| src = fetchFromGitHub { | ||
| owner = "supabase"; | ||
| repo = pname; | ||
| rev = "refs/tags/v${version}"; | ||
| hash = "sha256-j0iASDzmcZRLbHaS9ZNRWwzii7mcC+8wYHM0/mOLkbs="; | ||
| }; | ||
| # Derived version information | ||
| versions = lib.naturalSort (lib.attrNames supportedVersions); | ||
| latestVersion = lib.last versions; | ||
| numberOfVersions = builtins.length versions; | ||
| packages = builtins.attrValues ( | ||
| lib.mapAttrs (name: value: build name value.hash) supportedVersions | ||
| ); | ||
|
|
||
| # Build function for individual versions | ||
| build = | ||
| version: hash: | ||
| stdenv.mkDerivation rec { | ||
| inherit pname version; | ||
|
|
||
| buildInputs = [ postgresql ]; | ||
|
|
||
| src = fetchFromGitHub { | ||
| owner = "supabase"; | ||
| repo = pname; | ||
| rev = "refs/tags/v${version}"; | ||
| inherit hash; | ||
| }; | ||
|
|
||
| installPhase = '' | ||
| mkdir -p $out/lib | ||
| installPhase = '' | ||
| runHook preInstall | ||
|
|
||
| mkdir -p $out/{lib,share/postgresql/extension} | ||
|
|
||
| # Install shared library with version suffix | ||
| mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} | ||
|
|
||
| # Create version-specific control file | ||
| cat <<EOF > $out/share/postgresql/extension/${pname}--${version}.control | ||
| module_pathname = '$libdir/supautils' | ||
| relocatable = false | ||
| EOF | ||
|
|
||
| runHook postInstall | ||
| ''; | ||
|
|
||
| meta = with lib; { | ||
| description = "PostgreSQL extension for enhanced security"; | ||
| homepage = "https://github.com/supabase/${pname}"; | ||
| maintainers = with maintainers; [ steve-chavez ]; | ||
| inherit (postgresql.meta) platforms; | ||
| license = licenses.postgresql; | ||
| }; | ||
| }; | ||
| in | ||
| pkgs.buildEnv { | ||
| name = pname; | ||
| paths = packages; | ||
| pathsToLink = [ | ||
| "/lib" | ||
| "/share/postgresql/extension" | ||
| ]; | ||
| postBuild = '' | ||
| # Create symlinks to latest version for library and control file | ||
| ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} | ||
|
|
||
| install -D *${postgresql.dlSuffix} -t $out/lib | ||
| # Create default control file pointing to latest | ||
| { | ||
| echo "default_version = '${latestVersion}'" | ||
| cat $out/share/postgresql/extension/${pname}--${latestVersion}.control | ||
| } > $out/share/postgresql/extension/${pname}.control | ||
| ''; | ||
|
|
||
| meta = with lib; { | ||
| description = "PostgreSQL extension for enhanced security"; | ||
| homepage = "https://github.com/supabase/${pname}"; | ||
| maintainers = with maintainers; [ steve-chavez ]; | ||
| platforms = postgresql.meta.platforms; | ||
| license = licenses.postgresql; | ||
| passthru = { | ||
| inherit versions numberOfVersions; | ||
| pname = "${pname}-all"; | ||
| defaultSettings = { | ||
| session_preload_libraries = "supautils"; | ||
| "supautils.disable_program" = "true"; | ||
| "supautils.privileged_role" = "privileged_role"; | ||
| }; | ||
| version = | ||
| "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| { self, pkgs }: | ||
| let | ||
| pname = "supautils"; | ||
| inherit (pkgs) lib; | ||
| installedExtension = | ||
| postgresMajorVersion: | ||
| self.legacyPackages.${pkgs.system}."psql_${postgresMajorVersion}".exts."${pname}"; | ||
| versions = postgresqlMajorVersion: (installedExtension postgresqlMajorVersion).versions; | ||
| postgresqlWithExtension = | ||
| postgresql: | ||
| let | ||
| majorVersion = lib.versions.major postgresql.version; | ||
| pkg = pkgs.buildEnv { | ||
| name = "postgresql-${majorVersion}-${pname}"; | ||
| paths = [ | ||
| postgresql | ||
| postgresql.lib | ||
| (installedExtension majorVersion) | ||
| ]; | ||
| passthru = { | ||
| inherit (postgresql) version psqlSchema; | ||
| installedExtensions = [ (installedExtension majorVersion) ]; | ||
| lib = pkg; | ||
| withPackages = _: pkg; | ||
| withJIT = pkg; | ||
| withoutJIT = pkg; | ||
| }; | ||
| nativeBuildInputs = [ pkgs.makeWrapper ]; | ||
| pathsToLink = [ | ||
| "/" | ||
| "/bin" | ||
| "/lib" | ||
| ]; | ||
| postBuild = '' | ||
| wrapProgram $out/bin/postgres --set NIX_PGLIBDIR $out/lib | ||
| wrapProgram $out/bin/pg_ctl --set NIX_PGLIBDIR $out/lib | ||
| wrapProgram $out/bin/pg_upgrade --set NIX_PGLIBDIR $out/lib | ||
| ''; | ||
| }; | ||
| in | ||
| pkg; | ||
| psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15; | ||
| psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17; | ||
| in | ||
| self.inputs.nixpkgs.lib.nixos.runTest { | ||
| name = pname; | ||
| hostPkgs = pkgs; | ||
| nodes.server = | ||
| { config, ... }: | ||
| { | ||
| services.postgresql = { | ||
| enable = true; | ||
| package = (postgresqlWithExtension psql_15); | ||
| settings = { | ||
| shared_preload_libraries = "supautils"; | ||
| "supautils.privileged_extensions" = | ||
| "address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_buffercache, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers"; | ||
| }; | ||
| }; | ||
|
|
||
| specialisation.postgresql17.configuration = { | ||
| services.postgresql = { | ||
| package = lib.mkForce psql_17; | ||
| settings = { | ||
| "supautils.privileged_extensions" = | ||
| lib.mkForce "address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_buffercache, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql_check, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers"; | ||
| }; | ||
| }; | ||
|
|
||
| systemd.services.postgresql-migrate = { | ||
| serviceConfig = { | ||
| Type = "oneshot"; | ||
| RemainAfterExit = true; | ||
| User = "postgres"; | ||
| Group = "postgres"; | ||
| StateDirectory = "postgresql"; | ||
| WorkingDirectory = "${builtins.dirOf config.services.postgresql.dataDir}"; | ||
| }; | ||
| script = | ||
| let | ||
| oldPostgresql = psql_15; | ||
| newPostgresql = psql_17; | ||
| oldDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${oldPostgresql.psqlSchema}"; | ||
| newDataDir = "${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}"; | ||
| in | ||
| '' | ||
| if [[ ! -d ${newDataDir} ]]; then | ||
| install -d -m 0700 -o postgres -g postgres "${newDataDir}" | ||
| ${newPostgresql}/bin/initdb -D "${newDataDir}" | ||
| ${newPostgresql}/bin/pg_upgrade --old-datadir "${oldDataDir}" --new-datadir "${newDataDir}" \ | ||
| --old-bindir "${oldPostgresql}/bin" --new-bindir "${newPostgresql}/bin" \ | ||
| --old-options='-c shared_preload_libraries=supautils' --new-options='-c shared_preload_libraries=supautils' | ||
| else | ||
| echo "${newDataDir} already exists" | ||
| fi | ||
| ''; | ||
| }; | ||
|
|
||
| systemd.services.postgresql = { | ||
| after = [ "postgresql-migrate.service" ]; | ||
| requires = [ "postgresql-migrate.service" ]; | ||
| }; | ||
| }; | ||
| }; | ||
| testScript = | ||
| { nodes, ... }: | ||
| let | ||
| 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}" | ||
| ext_has_background_worker = ${ | ||
| if (installedExtension "15") ? hasBackgroundWorker then "True" else "False" | ||
| } | ||
| sql_test_directory = Path("${../../tests}") | ||
| pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}" | ||
|
|
||
| ${builtins.readFile ./lib.py} | ||
|
|
||
| start_all() | ||
|
|
||
| server.wait_for_unit("multi-user.target") | ||
| server.wait_for_unit("postgresql.service") | ||
|
|
||
| test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade) | ||
|
|
||
| with subtest("Check pg_regress with postgresql 15 after extension upgrade"): | ||
| test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name) | ||
|
|
||
| with subtest("switch to postgresql 17"): | ||
| server.succeed( | ||
| f"{pg17_configuration}/bin/switch-to-configuration test >&2" | ||
| ) | ||
|
|
||
| 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) | ||
| ''; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,10 @@ order by | |
| ----------------- | ||
| pg_cron | ||
| pgjwt | ||
| supautils | ||
| tsm_system_time | ||
| wal2json | ||
| (4 rows) | ||
| (5 rows) | ||
|
|
||
| /* | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| begin; | ||
| load 'supautils'; | ||
| -- verify that supautils configuration parameters exist | ||
| select current_setting('supautils.privileged_extensions', true) is not null as has_privileged_extensions; | ||
| has_privileged_extensions | ||
| --------------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| select current_setting('supautils.privileged_role', true) is not null as has_privileged_role; | ||
| has_privileged_role | ||
| --------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| -- switch to postgres role and verify access to settings | ||
| set role postgres; | ||
| select current_setting('supautils.privileged_extensions', true) as privileged_extensions; | ||
| privileged_extensions | ||
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
| address_standardizer, address_standardizer_data_us, autoinc, bloom, btree_gin, btree_gist, citext, cube, dblink, dict_int, dict_xsyn, earthdistance, fuzzystrmatch, hstore, http, hypopg, index_advisor, insert_username, intarray, isn, ltree, moddatetime, orioledb, pg_buffercache, pg_cron, pg_graphql, pg_hashids, pg_jsonschema, pg_net, pg_prewarm, pg_repack, pg_stat_monitor, pg_stat_statements, pg_tle, pg_trgm, pg_walinspect, pgaudit, pgcrypto, pgjwt, pgroonga, pgroonga_database, pgrouting, pgrowlocks, pgsodium, pgstattuple, pgtap, plcoffee, pljava, plls, plpgsql_check, plv8, postgis, postgis_raster, postgis_sfcgal, postgis_tiger_geocoder, postgis_topology, postgres_fdw, refint, rum, seg, sslinfo, supabase_vault, supautils, tablefunc, tcn, timescaledb, tsm_system_rows, tsm_system_time, unaccent, uuid-ossp, vector, wrappers | ||
| (1 row) | ||
|
|
||
| -- create a simple schema to verify normal operations work | ||
| create schema v; | ||
| create table v.test_table ( | ||
| id serial primary key, | ||
| data text | ||
| ); | ||
| insert into v.test_table (data) | ||
| values ('test1'), ('test2'); | ||
| select * from v.test_table order by id; | ||
| id | data | ||
| ----+------- | ||
| 1 | test1 | ||
| 2 | test2 | ||
| (2 rows) | ||
|
|
||
| rollback; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: supabase/postgres
Length of output: 563
🏁 Script executed:
# Read the full supautils.nix file to understand the build context wc -l nix/ext/supautils.nixRepository: supabase/postgres
Length of output: 85
🏁 Script executed:
Repository: supabase/postgres
Length of output: 701
🏁 Script executed:
# Search for upstream source definition in supautils.nix cat nix/ext/supautils.nixRepository: supabase/postgres
Length of output: 2861
🏁 Script executed:
Repository: supabase/postgres
Length of output: 43
🏁 Script executed:
Repository: supabase/postgres
Length of output: 1212
🌐 Web query:
supautils PostgreSQL extension GitHub supabase repository structure SQL files💡 Result:
supabase/supautils repo — summary (where the PostgreSQL extension SQL lives)
Source:
[1] supabase/supautils (GitHub repository) — repository file listing and README.
🏁 Script executed:
Repository: supabase/postgres
Length of output: 150
🏁 Script executed:
Repository: supabase/postgres
Length of output: 2320
🏁 Script executed:
Repository: supabase/postgres
Length of output: 1963
🏁 Script executed:
# Let me check the documentation about supautils updates to understand the structure cat nix/docs/update-extension.mdRepository: supabase/postgres
Length of output: 7041
🏁 Script executed:
Repository: supabase/postgres
Length of output: 2423
🏁 Script executed:
Repository: supabase/postgres
Length of output: 742
🌐 Web query:
site:github.com supabase/supautils repository structure src control.in💡 Result:
The supabase/supautils repository has a top-level src/ directory, but there is no file named control.in in that repository tree (no matching file found). [1][2]
Sources:
🏁 Script executed:
Repository: supabase/postgres
Length of output: 985
🏁 Script executed:
Repository: supabase/postgres
Length of output: 593
🏁 Script executed:
Repository: supabase/postgres
Length of output: 43
🌐 Web query:
supautils PostgreSQL extension Rust C source code SQL migration files💡 Result:
You can find the supautils source and SQL files on the project’s GitHub repo:
Additional package/extension metadata pages:
If you want I can list or show specific files (e.g., src/*.c, extension control/SQL files) from the repo — tell me which files or paths you want.
🏁 Script executed:
Repository: supabase/postgres
Length of output: 2153
Install upstream SQL migration files during installPhase.
The current installPhase creates a minimal control file but does not copy SQL migration scripts (e.g.,
supautils--*.sqlfiles) from the upstream source. Unlike the default_version (which is correctly added in postBuild), missing SQL files will causeCREATE EXTENSIONand upgrade operations to fail. Other extensions in this repo (pg_net, vault, pg_graphql, etc.) consistently copy these files. If the upstream supautils repository ships migration scripts in itssrc/directory, they must be installed alongside the compiled library.🤖 Prompt for AI Agents