feat: finalize ticket merging and speaker-aware imports

This commit is contained in:
Lago committed 2026-10-10 13:28:18 +02:00
1 parent 648daa0794
commit 4e71e9b797
35 files changed
+1772 -348

No files matched your search

@@ -0,0 +1,51 @@
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';