25 lines
1.2 KiB
PL/PgSQL
25 lines
1.2 KiB
PL/PgSQL
begin;
|
|
|
|
-- One exclusive sidebar identity. Ordinary company/profile edits cannot assign it.
|
|
create table public.caterium_sidebar_brand_assignment (
|
|
singleton boolean primary key default true check (singleton),
|
|
user_id uuid not null unique references auth.users(id) on delete cascade,
|
|
created_at timestamptz not null default now()
|
|
);
|
|
alter table public.caterium_sidebar_brand_assignment enable row level security;
|
|
revoke all on public.caterium_sidebar_brand_assignment from public,anon,authenticated;
|
|
grant all on public.caterium_sidebar_brand_assignment to service_role;
|
|
|
|
create function public.caterium_my_sidebar_brand()
|
|
returns jsonb language sql stable security definer set search_path=public,pg_temp as $$
|
|
select jsonb_build_object('variant',case when exists(
|
|
select 1 from public.caterium_sidebar_brand_assignment a
|
|
join auth.users u on u.id=a.user_id
|
|
where a.user_id=auth.uid() and u.email_confirmed_at is not null
|
|
) then 'solnce' else 'caterium' end)
|
|
$$;
|
|
revoke all on function public.caterium_my_sidebar_brand() from public,anon;
|
|
grant execute on function public.caterium_my_sidebar_brand() to authenticated;
|
|
notify pgrst,'reload schema';
|
|
commit;
|