Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
52 lines
2.2 KiB
PL/PgSQL
52 lines
2.2 KiB
PL/PgSQL
create function public._preserve_assigned_speaker_role()
|
|
returns trigger language plpgsql security definer set search_path = '' as $$
|
|
begin
|
|
if new.type = 'attendee' and exists (
|
|
select 1 from public.session_speakers speaker
|
|
join public.sessions talk on talk.id = speaker.session_id
|
|
join public.slots slot on slot.id = talk.slot_id and slot.event_id = talk.event_id
|
|
where speaker.contact_email = new.contact_email
|
|
and talk.event_id = new.event_id and slot.type = 'session'
|
|
) then
|
|
new.type := 'speaker'::public.registration_type;
|
|
end if;
|
|
return new;
|
|
end;
|
|
$$;
|
|
revoke all on function public._preserve_assigned_speaker_role() from public, anon, authenticated;
|
|
|
|
create trigger trg_registrations_assigned_speaker
|
|
before insert or update on public.registrations
|
|
for each row execute function public._preserve_assigned_speaker_role();
|
|
|
|
create or replace function public._trg_speaker_promote()
|
|
returns trigger language plpgsql security definer set search_path = '' as $$
|
|
begin
|
|
update public.registrations registration set type = 'speaker'::public.registration_type
|
|
from public.sessions talk join public.slots slot
|
|
on slot.id = talk.slot_id and slot.event_id = talk.event_id
|
|
where talk.id = new.session_id and slot.type = 'session'
|
|
and registration.event_id = talk.event_id
|
|
and registration.contact_email = new.contact_email
|
|
and registration.type = 'attendee';
|
|
return new;
|
|
end;
|
|
$$;
|
|
revoke all on function public._trg_speaker_promote() from public, anon, authenticated;
|
|
|
|
drop trigger session_speakers_speaker_promote on public.session_speakers;
|
|
create trigger session_speakers_speaker_promote
|
|
after insert or update on public.session_speakers
|
|
for each row execute function public._trg_speaker_promote();
|
|
|
|
update public.registrations registration set type = 'speaker'::public.registration_type
|
|
where registration.type = 'attendee' and exists (
|
|
select 1 from public.session_speakers speaker
|
|
join public.sessions talk on talk.id = speaker.session_id
|
|
join public.slots slot on slot.id = talk.slot_id and slot.event_id = talk.event_id
|
|
where speaker.contact_email = registration.contact_email
|
|
and talk.event_id = registration.event_id and slot.type = 'session'
|
|
);
|
|
|
|
notify pgrst, 'reload schema';
|