diff --git a/nix/withTmpDb.sh.in b/nix/withTmpDb.sh.in index 872fc69..35746f1 100644 --- a/nix/withTmpDb.sh.in +++ b/nix/withTmpDb.sh.in @@ -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.*" diff --git a/shell.nix b/shell.nix index 3575e3d..260d5e5 100644 --- a/shell.nix +++ b/shell.nix @@ -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; }) ]); diff --git a/src/privileged_extensions.c b/src/privileged_extensions.c index 653aaf7..1b31685 100644 --- a/src/privileged_extensions.c +++ b/src/privileged_extensions.c @@ -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)) { diff --git a/test/expected/privileged_extensions.out b/test/expected/privileged_extensions.out index 3914388..3c46ea7 100644 --- a/test/expected/privileged_extensions.out +++ b/test/expected/privileged_extensions.out @@ -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) + diff --git a/test/sql/privileged_extensions.sql b/test/sql/privileged_extensions.sql index 5b719ef..1ca2563 100644 --- a/test/sql/privileged_extensions.sql +++ b/test/sql/privileged_extensions.sql @@ -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';