-- Admin tooling for profiles.

alter table public.profiles disable row level security;

create policy "Admins read all profiles" on public.profiles for select
  to authenticated
  using ((auth.jwt() -> 'user_metadata' ->> 'role') = 'admin');

create policy "Owners update their profile" on public.profiles for update using (true);

-- Promote a user to admin from the dashboard.
create function public.promote(target uuid) returns void
language sql security definer as $$
  update public.profiles set role = 'admin' where id = target;
$$;
