Skip to content

Commit

Permalink
feat: handle pg_cron 1.4 -> 1.5 breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Jan 19, 2024
1 parent 94d6890 commit dfae89c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nix/withTmpDb.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ trap 'pg_ctl stop -m i && rm -rf "$tmpdir"' sigint sigterm exit

PGTZ=UTC initdb --no-locale --encoding=UTF8 --nosync -U "$PGUSER"

options="-F -c listen_addresses=\"\" -k $PGDATA -c shared_preload_libraries=\"pg_tle, supautils\" -c wal_level=logical"
options="-F -c listen_addresses=\"\" -k $PGDATA -c shared_preload_libraries=\"pg_cron, pg_tle, supautils\" -c wal_level=logical -c cron.database_name=postgres"

reserved_roles="supabase_storage_admin, anon, reserved_but_not_yet_created, authenticator*"
reserved_memberships="pg_read_server_files, pg_write_server_files, pg_execute_server_program, role_with_reserved_membership"
privileged_extensions="autoinc, citext, hstore, postgres_fdw, pg_tle"
privileged_extensions="autoinc, citext, hstore, pg_cron, pg_tle, postgres_fdw"
privileged_extensions_custom_scripts_path="$tmpdir/privileged_extensions_custom_scripts"
privileged_role="privileged_role"
privileged_role_allowed_configs="session_replication_role, pgrst.*, other.nested.*"
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let
postgresql_15
];
pgWithExt = { postgresql }: postgresql.withPackages (p: [
p.pg_cron
(callPackage ./nix/supautils.nix { inherit postgresql; extraMakeFlags = "TEST=1"; })
(callPackage ./nix/pg_tle.nix { inherit postgresql; })
]);
Expand Down
13 changes: 13 additions & 0 deletions src/privileged_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ void handle_create_extension(
}
}

// Handle pg_cron 1.4 -> 1.5 breaking change.
if (strcmp(stmt->extname, "pg_cron") == 0) {
ListCell *option_cell = NULL;

foreach (option_cell, stmt->options) {
DefElem *defel = (DefElem *)lfirst(option_cell);

if (strcmp(defel->defname, "schema") == 0) {
defel->arg = (Node *)makeString("pg_catalog");
}
}
}

// Run `CREATE EXTENSION`.
if (!superuser() && is_string_in_comma_delimited_string(
stmt->extname, privileged_extensions)) {
Expand Down
10 changes: 10 additions & 0 deletions test/expected/privileged_extensions.out
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,13 @@ select current_role;
extensions_role
(1 row)

\echo

-- can force pg_cron to be installed in pg_catalog
create extension pg_cron schema public;
select extnamespace::regnamespace from pg_extension where extname = 'pg_cron';
extnamespace
--------------
pg_catalog
(1 row)

5 changes: 5 additions & 0 deletions test/sql/privileged_extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ create extension file_fdw;
-- original role is restored on nested switch_to_superuser()
create extension autoinc;
select current_role;
\echo

-- can force pg_cron to be installed in pg_catalog
create extension pg_cron schema public;
select extnamespace::regnamespace from pg_extension where extname = 'pg_cron';

0 comments on commit dfae89c

Please sign in to comment.