begin;

create or replace function public.get_my_total_contributions()
returns bigint
language sql
stable
security invoker
set search_path = ''
as $$
  select coalesce(sum(payment.received_amount), 0)::bigint
  from public.sponsor_monthly_payments payment
  where payment.sponsor_id = (select auth.uid());
$$;

comment on function public.get_my_total_contributions() is
  'Returns the signed-in donor lifetime total of recorded received payments.';

revoke all on function public.get_my_total_contributions()
  from public, anon;
grant execute on function public.get_my_total_contributions()
  to authenticated;

notify pgrst, 'reload schema';

commit;
