create or replace function public.owns_speaker_session(p_session_id uuid) returns boolean language sql stable security definer set search_path = '' as $$ select public.current_email() is not null and exists ( select 1 from public.session_speakers assignment join public.sessions talk on talk.id = assignment.session_id join public.slots slot on slot.id = talk.slot_id and slot.event_id = talk.event_id join public.registrations registration on registration.event_id = talk.event_id and registration.contact_email = assignment.contact_email where assignment.session_id = p_session_id and assignment.contact_email = public.current_email() and registration.type in ('speaker', 'staff') and slot.type = 'session' ); $$; revoke all on function public.owns_speaker_session(uuid) from public, anon; grant execute on function public.owns_speaker_session(uuid) to authenticated, service_role; notify pgrst, 'reload schema';