File tree Expand file tree Collapse file tree
ansible/files/postgresql_extension_custom_scripts/pg_duckdb Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ grant usage on foreign data wrapper duckdb to duckdb_role;
Original file line number Diff line number Diff line change 44-- Both postgres (developer/admin) and service_role (runtime API) need to run
55-- DuckDB queries. We use a group role rather than cross-granting between them,
66-- which mirrors the supabase_privileged_role pattern.
7+ --
8+ -- The FDW grant (GRANT USAGE ON FOREIGN DATA WRAPPER duckdb TO duckdb_role) is
9+ -- handled by ansible/files/postgresql_extension_custom_scripts/pg_duckdb/after-create.sql
10+ -- rather than an event trigger, following the established pattern for postgres_fdw etc.
711DO $$
812BEGIN
913 IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = ' duckdb_role' ) THEN
1317 END IF;
1418END $$;
1519
16- -- Event trigger for pg_duckdb
17- -- Fires on CREATE EXTENSION pg_duckdb and grants FDW usage to duckdb_role.
18- -- This mirrors the pattern used for pg_net and pg_cron.
19- CREATE OR REPLACE FUNCTION extensions .grant_pg_duckdb_access()
20- RETURNS event_trigger
21- LANGUAGE plpgsql
22- AS $$
23- BEGIN
24- IF EXISTS (
25- SELECT 1
26- FROM pg_event_trigger_ddl_commands() AS ev
27- JOIN pg_extension AS ext
28- ON ev .objid = ext .oid
29- WHERE ext .extname = ' pg_duckdb'
30- )
31- THEN
32- GRANT USAGE ON FOREIGN DATA WRAPPER duckdb TO duckdb_role;
33- END IF;
34- END;
35- $$;
36-
37- CREATE EVENT TRIGGER issue_pg_duckdb_access
38- ON ddl_command_end
39- WHEN TAG IN (' CREATE EXTENSION' )
40- EXECUTE PROCEDURE extensions .grant_pg_duckdb_access ();
41-
42- COMMENT ON FUNCTION extensions.grant_pg_duckdb_access IS ' Grants access to pg_duckdb' ;
43-
44- -- Also apply immediately for existing installs where extension is already present
45- DO $$
46- BEGIN
47- IF EXISTS (SELECT FROM pg_extension WHERE extname = ' pg_duckdb' ) THEN
48- GRANT USAGE ON FOREIGN DATA WRAPPER duckdb TO duckdb_role;
49- END IF;
50- END $$;
51-
5220-- migrate:down
You can’t perform that action at this time.
0 commit comments