-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpgl_ddl_deploy--1.6--1.7.sql
50 lines (38 loc) · 1.65 KB
/
pgl_ddl_deploy--1.6--1.7.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* pgl_ddl_deploy--1.6--1.7.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION pgl_ddl_deploy" to load this file. \quit
CREATE OR REPLACE FUNCTION pgl_ddl_deploy.add_role(p_roleoid oid)
RETURNS boolean
LANGUAGE plpgsql
AS $function$
/******
Assuming roles doing DDL are not superusers, this function grants needed privileges
to run through the pgl_ddl_deploy DDL deployment.
This needs to be run on BOTH provider and subscriber.
******/
DECLARE
v_rec RECORD;
v_sql TEXT;
v_rsat_args TEXT;
BEGIN
FOR v_rec IN
SELECT quote_ident(rolname) AS rolname FROM pg_roles WHERE oid = p_roleoid
LOOP
v_rsat_args:=pg_get_function_identity_arguments('pglogical.replication_set_add_table'::REGPROC);
v_sql:='
GRANT USAGE ON SCHEMA pglogical TO '||v_rec.rolname||';
GRANT USAGE ON SCHEMA pgl_ddl_deploy TO '||v_rec.rolname||';
GRANT EXECUTE ON FUNCTION pglogical.replicate_ddl_command(text, text[]) TO '||v_rec.rolname||';
GRANT EXECUTE ON FUNCTION pglogical.replication_set_add_table(' || v_rsat_args || ') TO '||v_rec.rolname||';
GRANT EXECUTE ON FUNCTION pgl_ddl_deploy.sql_command_tags(text) TO '||v_rec.rolname||';
GRANT EXECUTE ON FUNCTION pgl_ddl_deploy.kill_blockers(pgl_ddl_deploy.signals, name, name) TO '||v_rec.rolname||';
GRANT INSERT, UPDATE, SELECT ON ALL TABLES IN SCHEMA pgl_ddl_deploy TO '||v_rec.rolname||';
GRANT USAGE ON ALL SEQUENCES IN SCHEMA pgl_ddl_deploy TO '||v_rec.rolname||';
GRANT SELECT ON ALL TABLES IN SCHEMA pglogical TO '||v_rec.rolname||';';
EXECUTE v_sql;
RETURN true;
END LOOP;
RETURN false;
END;
$function$
;