Skip to content

Commit e230745

Browse files
committed
fix: have pre/post ext setup to use ext customer scripts instead of triggers
1 parent 532e8f2 commit e230745

2 files changed

Lines changed: 5 additions & 36 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
grant usage on foreign data wrapper duckdb to duckdb_role;

migrations/db/migrations/20260309201836_pg_duckdb_grants.sql

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
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.
711
DO $$
812
BEGIN
913
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'duckdb_role') THEN
@@ -13,40 +17,4 @@ BEGIN
1317
END IF;
1418
END $$;
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

0 commit comments

Comments
 (0)