forked from windmill-labs/windmill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-db-as-superuser.sql
62 lines (50 loc) · 1.52 KB
/
init-db-as-superuser.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
DO
$do$
BEGIN
IF EXISTS (
select usesuper from pg_user where (usename = CURRENT_USER AND usesuper = 't')) OR (CURRENT_USER = 'cloudsqlsuperuser')
AND NOT EXISTS (
SELECT
FROM pg_catalog.pg_roles
WHERE rolname = 'windmill_user') THEN
LOCK TABLE pg_catalog.pg_roles;
CREATE ROLE windmill_user;
GRANT ALL
ON ALL TABLES IN SCHEMA public
TO windmill_user;
GRANT ALL PRIVILEGES
ON ALL SEQUENCES IN SCHEMA public
TO windmill_user;
ALTER DEFAULT PRIVILEGES
IN SCHEMA public
GRANT ALL ON TABLES TO windmill_user;
ALTER DEFAULT PRIVILEGES
IN SCHEMA public
GRANT ALL ON SEQUENCES TO windmill_user;
END IF;
END
$do$;
DO
$do$
BEGIN
IF EXISTS (select usesuper from pg_user where usename = CURRENT_USER AND usesuper = 't') OR (CURRENT_USER = 'cloudsqlsuperuser')
AND NOT EXISTS (
SELECT
FROM pg_catalog.pg_roles
WHERE rolname = 'windmill_admin') THEN
CREATE ROLE windmill_admin WITH BYPASSRLS;
GRANT ALL
ON ALL TABLES IN SCHEMA public
TO windmill_admin;
GRANT ALL PRIVILEGES
ON ALL SEQUENCES IN SCHEMA public
TO windmill_admin;
ALTER DEFAULT PRIVILEGES
IN SCHEMA public
GRANT ALL ON TABLES TO windmill_admin;
ALTER DEFAULT PRIVILEGES
IN SCHEMA public
GRANT ALL ON SEQUENCES TO windmill_admin;
END IF;
END
$do$;