Skip to content

Commit

Permalink
create auth functions if required only
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco committed Dec 18, 2023
1 parent 72ac92e commit bdc2293
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ defmodule Realtime.Tenants.Migrations.CreateRlsHelperFunctions do
$$ language sql stable;
""")

execute("create schema if not exists auth")

execute("""
create or replace function auth.role() returns text as $$
select nullif(current_setting('request.jwt.claim.role', true), '')::text;
$$ language sql stable;
do $func_exists$
begin if not exists(select * from pg_proc where proname = 'role')
then
create or replace function auth.uid() returns uuid as $function_def$
select nullif(current_setting('request.jwt.claim.sub', true), '')::uuid;
$function_def$ language sql stable;
end if;
end $func_exists$;
""")

execute("""
create or replace function auth.role() returns text as $$
select nullif(current_setting('request.jwt.claim.role', true), '')::text;
$$ language sql stable;
do $func_exists$
begin if not exists(select * from pg_proc where proname = 'role')
then
create function auth.role() returns text as $function_def$
select nullif(current_setting('request.jwt.claim.role', true), '')::text;
$function_def$ language sql stable;
end if;
end $func_exists$;
""")
end
end

0 comments on commit bdc2293

Please sign in to comment.