@@ -18,11 +18,23 @@ BEGIN
1818 END IF;
1919
2020 -- Install ROLES
21- EXECUTE ' CREATE ROLE ' || anon_role || ' NOLOGIN NOINHERIT' ;
22- EXECUTE ' CREATE ROLE ' || authenticated_role || ' NOLOGIN NOINHERIT' ;
23- EXECUTE ' CREATE ROLE ' || service_role || ' NOLOGIN NOINHERIT bypassrls' ;
21+ IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = anon_role) THEN
22+ EXECUTE ' CREATE ROLE ' || anon_role || ' NOLOGIN NOINHERIT' ;
23+ END IF;
24+
25+ IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = authenticated_role ) THEN
26+ EXECUTE ' CREATE ROLE ' || authenticated_role || ' NOLOGIN NOINHERIT' ;
27+ END IF;
28+
29+ IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = service_role) THEN
30+ EXECUTE ' CREATE ROLE ' || service_role || ' NOLOGIN NOINHERIT bypassrls' ;
31+ END IF;
32+
33+ IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = ' authenticator' ) THEN
34+ EXECUTE ' CREATE USER authenticator NOINHERIT' ;
35+ END IF;
36+
2437
25- create user authenticator noinherit;
2638 EXECUTE ' grant ' || anon_role || ' to authenticator' ;
2739 EXECUTE ' grant ' || authenticated_role || ' to authenticator' ;
2840 EXECUTE ' grant ' || service_role || ' to authenticator' ;
@@ -70,7 +82,6 @@ CREATE INDEX IF NOT EXISTS name_prefix_search ON storage.objects(name text_patte
7082
7183ALTER TABLE storage .objects ENABLE ROW LEVEL SECURITY;
7284
73- drop function if exists storage .foldername ;
7485CREATE OR REPLACE FUNCTION storage .foldername(name text )
7586 RETURNS text []
7687 LANGUAGE plpgsql
8394END
8495$function$;
8596
86- drop function if exists storage .filename ;
8797CREATE OR REPLACE FUNCTION storage .filename(name text )
8898 RETURNS text
8999 LANGUAGE plpgsql
96106END
97107$function$;
98108
99- drop function if exists storage .extension ;
100109CREATE OR REPLACE FUNCTION storage .extension(name text )
101110 RETURNS text
102111 LANGUAGE plpgsql
113122$function$;
114123
115124-- @todo can this query be optimised further?
116- drop function if exists storage .search ;
117125CREATE OR REPLACE FUNCTION storage .search(prefix text , bucketname text , limits int DEFAULT 100 , levels int DEFAULT 1 , offsets int DEFAULT 0 )
118126 RETURNS TABLE (
119127 name text ,
0 commit comments