Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- migrate:up
ALTER ROLE postgres SET local_preload_libraries = '$libdir/plugins/safeupdate';

ALTER ROLE postgres SET safeupdate.enabled = 0;


-- migrate:down

13 changes: 8 additions & 5 deletions nix/ext/pg-safeupdate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ let
runHook preInstall

mkdir -p $out/share/postgresql/extension

mkdir -p $out/lib/plugins
# Install versioned library
install -Dm755 ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
# we use the plugins path because loading libraries with `local_preload_libraries` is restricted to this path only, see https://postgresqlco.nf/doc/en/param/local_preload_libraries/
install -Dm755 ${pname}${postgresql.dlSuffix} $out/lib/plugins/${pname}-${version}${postgresql.dlSuffix}
Comment thread
encima marked this conversation as resolved.
Comment thread
encima marked this conversation as resolved.

runHook postInstall
'';
Expand Down Expand Up @@ -65,15 +66,16 @@ pkgs.buildEnv {
paths = packages;
nativeBuildInputs = [ makeWrapper ];
pathsToLink = [
"/lib"
"/lib/plugins"
"/share/postgresql/extension"
];
postBuild = ''
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/plugins/${pname}${postgresql.dlSuffix}
ln -sfn plugins/${pname}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}

# checks
(set -x
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
test "$(ls -A $out/lib/plugins/${pname}*${postgresql.dlSuffix} | wc -l)" = "${
toString (numberOfVersionsBuilt + 1)
}"
)
Expand All @@ -88,6 +90,7 @@ pkgs.buildEnv {
inherit pname latestOnly;
defaultSettings = {
shared_preload_libraries = [ "safeupdate" ];
local_preload_libraries = [ "safeupdate" ];
Comment thread
encima marked this conversation as resolved.
};
pgRegressTestName = "pg-safeupdate";
version =
Expand Down
2 changes: 1 addition & 1 deletion nix/tests/expected/pg-safeupdate.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load 'safeupdate';
load '$libdir/plugins/safeupdate';
set safeupdate.enabled=1;
create schema v;
create table v.foo(
Expand Down
6 changes: 3 additions & 3 deletions nix/tests/expected/roles.out
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ select
from pg_roles r
where rolname not in ('pg_create_subscription', 'pg_maintain', 'pg_use_reserved_connections')
order by rolname;
rolname | rolconfig
----------------------------+---------------------------------------------------------------------------------
rolname | rolconfig
----------------------------+-------------------------------------------------------------------------------------------------------------------------------
anon | {statement_timeout=3s}
authenticated | {statement_timeout=8s}
authenticator | {session_preload_libraries=safeupdate,statement_timeout=8s,lock_timeout=8s}
Expand All @@ -83,7 +83,7 @@ order by rolname;
pgsodium_keyiduser |
pgsodium_keymaker |
pgtle_admin |
postgres | {"search_path=\"\\$user\", public, extensions"}
postgres | {"search_path=\"\\$user\", public, extensions","local_preload_libraries=\"$libdir/plugins/safeupdate\"",safeupdate.enabled=0}
service_role |
supabase_admin | {"search_path=\"$user\", public, auth, extensions",log_statement=none}
supabase_auth_admin | {search_path=auth,idle_in_transaction_session_timeout=60000,log_statement=none}
Expand Down
6 changes: 3 additions & 3 deletions nix/tests/expected/z_multigres-orioledb-17_roles.out
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ select
from pg_roles r
where rolname not in ('pg_create_subscription', 'pg_maintain', 'pg_use_reserved_connections')
order by rolname;
rolname | rolconfig
----------------------------+---------------------------------------------------------------------------------
rolname | rolconfig
----------------------------+-------------------------------------------------------------------------------------------------------------------------------
anon | {statement_timeout=3s}
authenticated | {statement_timeout=8s}
authenticator | {session_preload_libraries=safeupdate,statement_timeout=8s,lock_timeout=8s}
Expand All @@ -77,7 +77,7 @@ order by rolname;
pg_write_server_files |
pgbouncer |
pgtle_admin |
postgres | {"search_path=\"\\$user\", public, extensions"}
postgres | {"search_path=\"\\$user\", public, extensions","local_preload_libraries=\"$libdir/plugins/safeupdate\"",safeupdate.enabled=0}
service_role |
supabase_admin | {"search_path=\"\\$user\", public, auth, extensions",log_statement=none}
supabase_auth_admin | {search_path=auth,idle_in_transaction_session_timeout=60000,log_statement=none}
Expand Down
2 changes: 1 addition & 1 deletion nix/tests/sql/pg-safeupdate.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load 'safeupdate';
load '$libdir/plugins/safeupdate';

set safeupdate.enabled=1;

Expand Down
Loading