diff --git a/storage_v1.19.1/migrations/tenant/0002-storage-schema.sql b/storage_v1.19.1/migrations/tenant/0002-storage-schema.sql index d91586f..91fa033 100644 --- a/storage_v1.19.1/migrations/tenant/0002-storage-schema.sql +++ b/storage_v1.19.1/migrations/tenant/0002-storage-schema.sql @@ -18,11 +18,19 @@ BEGIN END IF; -- Install ROLES - EXECUTE 'CREATE ROLE ' || anon_role || ' NOLOGIN NOINHERIT'; - EXECUTE 'CREATE ROLE ' || authenticated_role || ' NOLOGIN NOINHERIT'; - EXECUTE 'CREATE ROLE ' || service_role || ' NOLOGIN NOINHERIT bypassrls'; + EXECUTE 'CREATE ROLE IF NOT EXISTS ' || anon_role || ' NOLOGIN NOINHERIT'; + EXECUTE 'CREATE ROLE IF NOT EXISTS ' || authenticated_role || ' NOLOGIN NOINHERIT'; + EXECUTE 'CREATE ROLE IF NOT EXISTS ' || service_role || ' NOLOGIN NOINHERIT bypassrls'; + + -- create user authenticator noinherit; + IF NOT EXISTS ( + SELECT 1 + FROM pg_roles + WHERE rolname = 'authenticator' + ) THEN + EXECUTE 'create user authenticator noinherit;'; + END IF; - create user authenticator noinherit; EXECUTE 'grant ' || anon_role || ' to authenticator'; EXECUTE 'grant ' || authenticated_role || ' to authenticator'; EXECUTE 'grant ' || service_role || ' to authenticator';