feat: add manual feedback AI summaries and secure leaderboard scoring

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]>
This commit is contained in:
committed 2026-10-15 19:06:10 +02:00
1 parent 407b878e23
commit 821907b164
37 files changed
+1640 -77

No files matched your search

@@ -0,0 +1,36 @@
create table public.llm_settings (
id boolean primary key default true check (id),
endpoint text not null,
model text not null,
api_key text not null default '',
updated_at timestamptz not null default now()
);
alter table public.llm_settings enable row level security;
revoke all on public.llm_settings from public, anon, authenticated;
grant select, insert, update on public.llm_settings to service_role;
create table public.feedback_summaries (
scope text not null check (scope in ('event', 'session')),
target_id uuid not null,
event_id uuid not null references public.events(id) on delete cascade,
session_id uuid references public.sessions(id) on delete cascade,
summary text not null check (length(summary) between 1 and 20000),
response_count integer not null check (response_count > 0),
source_fingerprint text not null,
model text not null,
generated_at timestamptz not null default now(),
primary key (scope, target_id),
check ((scope = 'event' and session_id is null and target_id = event_id)
or (scope = 'session' and session_id is not null and target_id = session_id))
);
create index feedback_summaries_event_id_idx on public.feedback_summaries(event_id);
alter table public.feedback_summaries enable row level security;
revoke all on public.feedback_summaries from public, anon, authenticated;
grant select on public.feedback_summaries to authenticated;
grant select, insert, update on public.feedback_summaries to service_role;
create policy feedback_summaries_admin_read on public.feedback_summaries
for select to authenticated using ((select public.is_admin()));
revoke execute on function public.evaluate_session_feedback(uuid) from public, anon, authenticated;
@@ -0,0 +1,159 @@
create or replace function public._points_eligible(p_event_id uuid, p_contact_email text)
returns boolean
language sql stable security definer set search_path = '' as $$
select exists (
select 1 from public.registrations r
join public.contacts c on c.email = r.contact_email
where r.event_id = p_event_id and r.contact_email = p_contact_email
and r.type <> 'staff' and not c.is_admin and c.email not like '%@appe.at'
);
$$;
create or replace function public._sync_leaderboard(p_event_id uuid, p_contact_email text)
returns void
language plpgsql security definer set search_path = '' as $$
begin
if not public._points_eligible(p_event_id, p_contact_email) then
delete from public.leaderboard where event_id = p_event_id and contact_email = p_contact_email;
return;
end if;
insert into public.leaderboard (event_id, contact_email, full_name, points)
select r.event_id, c.email, c.full_name, r.points
from public.registrations r join public.contacts c on c.email = r.contact_email
where r.event_id = p_event_id and r.contact_email = p_contact_email
on conflict (event_id, contact_email) do update
set full_name = excluded.full_name, points = excluded.points, updated_at = now();
end;
$$;
create or replace function public._award_points(p_event_id uuid, p_contact_email text, p_delta integer, p_category text)
returns void
language plpgsql security definer set search_path = '' as $$
begin
perform 1 from public.registrations
where event_id = p_event_id and contact_email = p_contact_email for update;
if not found or not public._points_eligible(p_event_id, p_contact_email) then
return;
end if;
update public.registrations set points = greatest(0, points + p_delta)
where event_id = p_event_id and contact_email = p_contact_email;
insert into public.points_log (event_id, contact_email, delta, category)
values (p_event_id, p_contact_email, p_delta, p_category);
end;
$$;
create or replace function public._guard_registration_points()
returns trigger
language plpgsql security definer set search_path = '' as $$
begin
if new.type = 'staff' or exists (
select 1 from public.contacts c where c.email = new.contact_email
and (c.is_admin or c.email like '%@appe.at')
) then
new.points := 0;
end if;
return new;
end;
$$;
create trigger z_registrations_points_guard
before insert or update on public.registrations
for each row execute function public._guard_registration_points();
create or replace function public._refresh_registration_leaderboard()
returns trigger
language plpgsql security definer set search_path = '' as $$
begin
if tg_op = 'DELETE' then
delete from public.leaderboard where event_id = old.event_id and contact_email = old.contact_email;
return old;
end if;
if tg_op = 'UPDATE' then
if old.event_id is distinct from new.event_id or old.contact_email is distinct from new.contact_email then
delete from public.leaderboard where event_id = old.event_id and contact_email = old.contact_email;
end if;
end if;
perform public._sync_leaderboard(new.event_id, new.contact_email);
return new;
end;
$$;
create trigger registrations_leaderboard_refresh
after insert or update or delete on public.registrations
for each row execute function public._refresh_registration_leaderboard();
create or replace function public._refresh_contact_leaderboards()
returns trigger
language plpgsql security definer set search_path = '' as $$
declare
registration_event uuid;
begin
if new.is_admin or new.email like '%@appe.at' then
update public.registrations set points = 0 where contact_email = new.email;
end if;
for registration_event in select event_id from public.registrations where contact_email = new.email loop
perform public._sync_leaderboard(registration_event, new.email);
end loop;
return new;
end;
$$;
create trigger contacts_leaderboard_refresh
after update of is_admin, full_name on public.contacts
for each row execute function public._refresh_contact_leaderboards();
create or replace function public.get_leaderboard()
returns table (event_id uuid, contact_email text, full_name text, points integer)
language sql stable security definer set search_path = '' as $$
select l.event_id, l.contact_email, l.full_name, l.points
from public.leaderboard l
join public.events e on e.id = l.event_id and e.is_active
join public.registrations r on r.event_id = l.event_id and r.contact_email = l.contact_email
join public.contacts c on c.email = r.contact_email
where r.type <> 'staff' and not c.is_admin and c.email not like '%@appe.at'
order by l.points desc, l.full_name asc, l.contact_email asc;
$$;
do $$
declare
definition text := pg_get_functiondef('public.submit_feedback(uuid,integer,text)'::regprocedure);
original text := 'v_earned := case when v_clean is not null then 10 else 5 end;';
begin
if strpos(definition, original) = 0 then
raise exception 'submit_feedback scoring definition changed; review migration';
end if;
execute replace(definition, original,
'v_earned := case when not public._points_eligible(v_event_id, v_email) then 0 when v_clean is not null then 10 else 5 end;');
end;
$$;
update public.registrations r set points = 0
from public.contacts c where c.email = r.contact_email
and (r.type = 'staff' or c.is_admin or c.email like '%@appe.at') and r.points <> 0;
delete from public.leaderboard l where not public._points_eligible(l.event_id, l.contact_email);
insert into public.leaderboard (event_id, contact_email, full_name, points)
select r.event_id, c.email, c.full_name, r.points
from public.registrations r join public.contacts c on c.email = r.contact_email
where r.type <> 'staff' and not c.is_admin and c.email not like '%@appe.at'
on conflict (event_id, contact_email) do update
set full_name = excluded.full_name, points = excluded.points, updated_at = now();
revoke all on function public._points_eligible(uuid,text),
public._award_points(uuid,text,integer,text), public._sync_leaderboard(uuid,text),
public._guard_registration_points(), public._refresh_registration_leaderboard(),
public._refresh_contact_leaderboards() from public, anon, authenticated;
revoke all on function public.get_leaderboard() from public, anon;
grant execute on function public.get_leaderboard() to authenticated;
do $$
begin
if exists (select 1 from pg_publication where pubname = 'supabase_realtime')
and not exists (
select 1 from pg_publication_tables
where pubname = 'supabase_realtime' and schemaname = 'public' and tablename = 'leaderboard'
) then
alter publication supabase_realtime add table public.leaderboard;
end if;
end;
$$;
@@ -0,0 +1,61 @@
\set ON_ERROR_STOP on
begin;
create function pg_temp.assert_summary(condition boolean, label text) returns void
language plpgsql as $$ begin
if condition is distinct from true then raise exception 'FAIL: %', label; end if;
raise notice 'PASS: %', label;
end; $$;
create temp table ai_fixture as select gen_random_uuid() event_id,
'ai-admin-' || gen_random_uuid() || '@example.invalid' admin_email,
'ai-attendee-' || gen_random_uuid() || '@example.invalid' attendee_email;
insert into public.events(id, name, start_date, end_date, is_active)
select event_id, 'AI test event', '2026-10-23', '2026-10-23', false from ai_fixture;
insert into public.contacts(email, full_name, is_admin)
select admin_email, 'AI test admin', true from ai_fixture
union all select attendee_email, 'AI test attendee', false from ai_fixture;
select pg_temp.assert_summary(
(select bool_and(relrowsecurity) from pg_class where oid in ('public.llm_settings'::regclass, 'public.feedback_summaries'::regclass)),
'RLS enabled on both AI tables');
select pg_temp.assert_summary(
not has_table_privilege('anon', 'public.llm_settings', 'select')
and not has_table_privilege('authenticated', 'public.llm_settings', 'select')
and not has_table_privilege('authenticated', 'public.llm_settings', 'insert,update,delete'),
'client roles cannot access LLM settings or credentials');
select pg_temp.assert_summary(
not has_table_privilege('anon', 'public.feedback_summaries', 'select')
and not has_table_privilege('authenticated', 'public.feedback_summaries', 'insert,update,delete'),
'anonymous reads and all client summary writes are denied');
select pg_temp.assert_summary(
not has_function_privilege('authenticated', 'public.evaluate_session_feedback(uuid)', 'execute')
and not has_function_privilege('anon', 'public.evaluate_session_feedback(uuid)', 'execute'),
'obsolete AI stub cannot be called by clients');
select event_id::text as ai_event_id, admin_email as ai_admin_email, attendee_email as ai_attendee_email from ai_fixture \gset
set local role service_role;
insert into public.llm_settings(id, endpoint, model, api_key)
values (true, 'https://llm.example/v1/chat/completions', 'test', 'fixture-only-key')
on conflict (id) do update set model = excluded.model;
insert into public.feedback_summaries(scope, target_id, event_id, summary, response_count, source_fingerprint, model)
values ('event', :'ai_event_id', :'ai_event_id', 'Fixture summary', 1, 'fixture-hash', 'test');
reset role;
select pg_temp.assert_summary(
exists(select 1 from public.feedback_summaries where event_id = :'ai_event_id'),
'service role can persist summaries');
set local role authenticated;
select set_config('request.jwt.claims', json_build_object('email', :'ai_attendee_email')::text, true);
select pg_temp.assert_summary(
not exists(select 1 from public.feedback_summaries where event_id = :'ai_event_id'),
'non-admin cannot read a summary');
select set_config('request.jwt.claims', json_build_object('email', :'ai_admin_email')::text, true);
select pg_temp.assert_summary(
(select summary = 'Fixture summary' from public.feedback_summaries where event_id = :'ai_event_id'),
'admin can read the saved summary');
reset role;
delete from public.events where id = :'ai_event_id';
select pg_temp.assert_summary(
not exists(select 1 from public.feedback_summaries where event_id = :'ai_event_id'),
'deleting the event cascades its summaries');
rollback;
+182
View File
@@ -0,0 +1,182 @@
\set ON_ERROR_STOP on
begin;
create temporary table leaderboard_results (name text);
create function pg_temp.assert_board(p_condition boolean, p_name text) returns void
language plpgsql as $$
begin
if p_condition is distinct from true then raise exception 'FAIL: %', p_name; end if;
insert into leaderboard_results values (p_name);
end;
$$;
update public.events set is_active = false where is_active;
insert into public.events (id, name, start_date, end_date, is_active)
values ('a0150000-0000-0000-0000-000000000001', 'Leaderboard regression', current_date, current_date, true),
('a0150000-0000-0000-0000-000000000002', 'Other event', current_date, current_date, false);
insert into public.contacts (email, full_name, is_admin)
values ('[email protected]', 'Player', false), ('[email protected]', 'Peer', false),
('[email protected]', 'Other', false), ('[email protected]', 'Speaker', false),
('[email protected]', 'Staff', false), ('[email protected]', 'Admin', true),
('[email protected]', 'Domain Admin', false), ('[email protected]', 'Orphan', false);
insert into public.registrations (event_id, contact_email, type, qr_token, points)
select 'a0150000-0000-0000-0000-000000000001'::uuid, email,
case when email = '[email protected]' then 'staff'
when email = '[email protected]' then 'speaker' else 'attendee' end::public.registration_type,
'LB-' || email, case when is_admin or email = '[email protected]' then 99 else 0 end
from public.contacts where email in ('[email protected]', '[email protected]', '[email protected]',
'[email protected]', '[email protected]', '[email protected]', '[email protected]');
insert into public.registrations (event_id, contact_email, type, qr_token, points)
values ('a0150000-0000-0000-0000-000000000002', '[email protected]', 'attendee', 'LB-OTHER-EVENT', 50);
insert into public.slots (id, event_id, name, slot_date, start_time, end_time, type)
values (-151001, 'a0150000-0000-0000-0000-000000000001', 'Talk', current_date, '09:00', '10:00', 'session'),
(-151002, 'a0150000-0000-0000-0000-000000000001', 'Service', current_date, '10:00', '11:00', 'service_session');
insert into public.sessions (id, event_id, slot_id, title)
values ('a0150000-0000-0000-0000-000000000011', 'a0150000-0000-0000-0000-000000000001', -151001, 'Talk one'),
('a0150000-0000-0000-0000-000000000012', 'a0150000-0000-0000-0000-000000000001', -151001, 'Talk two'),
('a0150000-0000-0000-0000-000000000013', 'a0150000-0000-0000-0000-000000000001', -151002, 'Service');
do $$
declare
event_one uuid := 'a0150000-0000-0000-0000-000000000001';
talk_one uuid := 'a0150000-0000-0000-0000-000000000011';
talk_two uuid := 'a0150000-0000-0000-0000-000000000012';
excluded_email text;
feedback_result record;
begin
perform pg_temp.assert_board((select bool_and(points = 0) from public.registrations
where contact_email in ('[email protected]','[email protected]','[email protected]')), 'excluded inserts force zero');
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform public.checkin_attendee(talk_one, '[email protected]');
perform pg_temp.assert_board((select points = 10 and checked_in from public.registrations where contact_email = '[email protected]'), 'check-in awards ten');
perform pg_temp.assert_board((select already and points = 10 from public.checkin_attendee(talk_one, '[email protected]')), 'check-in idempotent');
perform public.checkin_attendee(talk_one, '[email protected]');
perform public.checkin_attendee(talk_one, '[email protected]');
perform pg_temp.assert_board((select points = 10 from public.registrations where contact_email = '[email protected]'), 'nonadmin speaker earns points');
foreach excluded_email in array array['[email protected]','[email protected]','[email protected]'] loop
perform public.checkin_attendee(talk_one, 'LB-' || excluded_email);
end loop;
begin
perform public.checkin_attendee('a0150000-0000-0000-0000-000000000013', '[email protected]');
raise exception 'service check-in accepted';
exception when raise_exception then
if sqlerrm <> 'service sessions cannot be checked in' then raise; end if;
end;
perform pg_temp.assert_board(true, 'service check-in rejected');
foreach excluded_email in array array['[email protected]','[email protected]','[email protected]'] loop
perform set_config('request.jwt.claims', json_build_object('email', excluded_email)::text, true);
select * into feedback_result from public.submit_feedback(talk_one, 5, 'Review');
perform pg_temp.assert_board(feedback_result.earned = 0 and feedback_result.points = 0, excluded_email || ' feedback earns zero');
perform public._award_points(event_one, excluded_email, 7, 'connection');
perform public._award_points(event_one, excluded_email, 2, 'talk_networking');
perform public._award_points(event_one, excluded_email, 100, 'admin');
end loop;
perform pg_temp.assert_board(not exists (select 1 from public.points_log where contact_email in
('[email protected]','[email protected]','[email protected]')), 'no excluded award logs');
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform pg_temp.assert_board((select earned = 5 and points = 15 from public.submit_feedback(talk_one, 4, null)), 'rating awards five');
perform pg_temp.assert_board((select earned = 0 and points = 15 from public.submit_feedback(talk_one, 5, 'Updated')), 'feedback idempotent');
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform public.checkin_attendee(talk_two, '[email protected]');
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform pg_temp.assert_board((select earned = 10 and points = 35 from public.submit_feedback(talk_two, 5, 'Useful')), 'comment awards ten');
perform pg_temp.assert_board((select points = 35 from public.submit_event_feedback(5, 'Good event')), 'event feedback does not award points');
end;
$$;
insert into public.connections (id, event_id, from_email, to_email)
values ('a0150000-0000-0000-0000-000000000021', 'a0150000-0000-0000-0000-000000000001', '[email protected]', '[email protected]'),
('a0150000-0000-0000-0000-000000000022', 'a0150000-0000-0000-0000-000000000001', '[email protected]', '[email protected]'),
('a0150000-0000-0000-0000-000000000023', 'a0150000-0000-0000-0000-000000000001', '[email protected]', '[email protected]');
do $$
begin
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform pg_temp.assert_board((select shared_talk from public.accept_connection('a0150000-0000-0000-0000-000000000021')), 'shared talk detected');
perform pg_temp.assert_board((select points = 42 from public.registrations where contact_email = '[email protected]'), 'eligible peer earns seven with staff connection');
perform pg_temp.assert_board((select points = 0 from public.registrations where contact_email = '[email protected]'), 'staff connection earns zero');
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform public.accept_connection('a0150000-0000-0000-0000-000000000022');
perform pg_temp.assert_board((select points = 49 from public.registrations where contact_email = '[email protected]'), 'sender earns connection plus bonus');
perform pg_temp.assert_board((select points = 17 from public.registrations where contact_email = '[email protected]' and event_id = 'a0150000-0000-0000-0000-000000000001'), 'recipient earns connection plus bonus');
begin
perform public.accept_connection('a0150000-0000-0000-0000-000000000022');
raise exception 'repeated acceptance allowed';
exception when raise_exception then
if sqlerrm <> 'request already resolved' then raise; end if;
end;
perform pg_temp.assert_board(true, 'connection one-shot');
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform pg_temp.assert_board((select not shared_talk from public.accept_connection('a0150000-0000-0000-0000-000000000023')), 'no shared-talk bonus without shared check-in');
perform pg_temp.assert_board((select points = 5 from public.registrations where contact_email = '[email protected]'), 'ordinary connection earns five');
perform pg_temp.assert_board((select points = 50 from public.registrations where event_id = 'a0150000-0000-0000-0000-000000000002'), 'other event untouched');
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
perform public.adjust_points('[email protected]', -999, 'Floor test');
perform pg_temp.assert_board((select points = 0 from public.registrations where contact_email = '[email protected]'), 'points floored at zero');
perform public.adjust_points('[email protected]', 3, 'Correction');
perform pg_temp.assert_board((select points = 57 from public.registrations where contact_email = '[email protected]'), 'admin adjustment updates player');
perform public.adjust_points('[email protected]', 100, 'Must not award');
perform public.adjust_points('[email protected]', 100, 'Must not award');
perform public._award_points('a0150000-0000-0000-0000-000000000001', '[email protected]', 100, 'admin');
perform pg_temp.assert_board(not exists (select 1 from public.points_log where contact_email in
('[email protected]','[email protected]','[email protected]','[email protected]')), 'adjustments cannot award excluded or missing registrations');
perform pg_temp.assert_board(not exists (select 1 from public.leaderboard l join public.registrations r using (event_id, contact_email) where l.points <> r.points), 'leaderboard matches registration totals');
perform pg_temp.assert_board((select contact_email = '[email protected]' from public.get_leaderboard() limit 1), 'highest points rank first');
perform pg_temp.assert_board(not exists (select 1 from public.get_leaderboard() where event_id <> 'a0150000-0000-0000-0000-000000000001'), 'active event only');
end;
$$;
update public.registrations set points = 99 where contact_email = '[email protected]';
select pg_temp.assert_board((select points = 0 from public.registrations where contact_email = '[email protected]'), 'direct staff edits forced to zero');
update public.registrations set type = 'staff' where contact_email = '[email protected]';
select pg_temp.assert_board((select points = 0 from public.registrations where contact_email = '[email protected]'), 'staff promotion clears points');
select pg_temp.assert_board(not exists (select 1 from public.leaderboard where contact_email = '[email protected]'), 'staff promotion removes ranking');
update public.contacts set is_admin = true where email = '[email protected]';
select pg_temp.assert_board((select bool_and(points = 0) from public.registrations where contact_email = '[email protected]'), 'admin promotion clears all event balances');
select pg_temp.assert_board(not exists (select 1 from public.leaderboard where contact_email = '[email protected]'), 'admin promotion removes all rankings');
select pg_temp.assert_board(exists (select 1 from public.points_log where contact_email = '[email protected]'), 'historical audit retained');
update public.registrations set type = 'attendee', points = 7 where contact_email = '[email protected]';
update public.registrations set points = 7 where contact_email = '[email protected]';
update public.contacts set full_name = 'Tied' where email in ('[email protected]', '[email protected]');
select pg_temp.assert_board((select bool_and(full_name = 'Tied') from public.leaderboard where contact_email in ('[email protected]','[email protected]')), 'name changes refresh mirror');
select pg_temp.assert_board((select array_agg(contact_email) = array['[email protected]','[email protected]'] from public.get_leaderboard() where points = 7), 'deterministic tie order');
insert into public.leaderboard (event_id, contact_email, full_name, points)
values ('a0150000-0000-0000-0000-000000000001', '[email protected]', 'Stray staff', 999),
('a0150000-0000-0000-0000-000000000001', '[email protected]', 'Stray admin', 999),
('a0150000-0000-0000-0000-000000000001', '[email protected]', 'Stray orphan', 999);
select pg_temp.assert_board(not exists (select 1 from public.get_leaderboard() where contact_email in ('[email protected]','[email protected]','[email protected]')), 'read defense excludes stale staff admin and orphan rows');
select public._sync_leaderboard('a0150000-0000-0000-0000-000000000001', '[email protected]');
select pg_temp.assert_board(not exists (select 1 from public.leaderboard where contact_email = '[email protected]'), 'sync removes stale ranking');
delete from public.registrations where contact_email = '[email protected]';
select pg_temp.assert_board(not exists (select 1 from public.leaderboard where contact_email = '[email protected]'), 'registration deletion removes ranking');
select pg_temp.assert_board(not has_function_privilege('authenticated','public._award_points(uuid,text,integer,text)','execute')
and not has_function_privilege('anon','public._award_points(uuid,text,integer,text)','execute'), 'API roles cannot forge awards');
select pg_temp.assert_board(not has_function_privilege('authenticated','public._sync_leaderboard(uuid,text)','execute'), 'API roles cannot call sync helper');
select pg_temp.assert_board(has_function_privilege('authenticated','public.get_leaderboard()','execute')
and not has_function_privilege('anon','public.get_leaderboard()','execute'), 'rankings require authentication');
select pg_temp.assert_board(exists (select 1 from pg_publication_tables where pubname = 'supabase_realtime' and tablename = 'leaderboard' and schemaname = 'public'), 'Realtime publication enabled');
grant insert on leaderboard_results to authenticated;
select set_config('request.jwt.claims', '{"email":"[email protected]","role":"authenticated"}', true);
set local role authenticated;
select pg_temp.assert_board(exists (select 1 from public.get_leaderboard()), 'authenticated API role can read rankings');
do $$
begin
begin
perform public._award_points('a0150000-0000-0000-0000-000000000001', '[email protected]', 9999, 'admin');
raise exception 'forged award accepted';
exception when insufficient_privilege then null;
end;
perform pg_temp.assert_board(true, 'direct helper invocation denied');
begin
perform public.adjust_points('[email protected]', 9999, 'Not admin');
raise exception 'unauthorized adjustment accepted';
exception when raise_exception then
if sqlerrm <> 'admin only' then raise; end if;
end;
perform pg_temp.assert_board(true, 'nonadmin adjustment rejected');
end;
$$;
reset role;
select count(*) as passed_assertions from leaderboard_results;
rollback;
@@ -86,7 +86,7 @@ create temporary table merge_result as select public.merge_tickets(source_id,tar
reset role;
select pg_temp.assert_merge((select (result->>'sessions_transferred')::integer=2 from merge_result), 'two source assignments transferred');
select pg_temp.assert_merge(not exists(select 1 from public.registrations where id=(select source_id from merge_fixture)), 'source registration deleted');
select pg_temp.assert_merge((select type='staff' and checked_in and points=17 and qr_token=id::text and external_id='pretix-target'
select pg_temp.assert_merge((select type='staff' and checked_in and points=0 and qr_token=id::text and external_id='pretix-target'
from public.registrations where id=(select target_id from merge_fixture)), 'target staff status QR and attendance preserved');
select pg_temp.assert_merge((select count(*)=2 from public.session_speakers where contact_email=(select target_email from merge_fixture)
and session_id in(select session_a from merge_fixture union all select session_shared from merge_fixture)), 'replacement links inserted without duplicates');
@@ -356,7 +356,7 @@ select pg_temp.assert_sessionize_guard(
'stale slot/session outside range are retained after successful imports');
select pg_temp.assert_sessionize_guard(
exists (select 1 from public.registrations r join sessionize_guard_fixture f on f.event_id = r.event_id
where r.contact_email = staff_email and r.type = 'staff' and r.points = 22 and r.checked_in)
where r.contact_email = staff_email and r.type = 'staff' and r.points = 0 and r.checked_in)
and exists (select 1 from public.registrations r join sessionize_guard_fixture f on f.event_id = r.event_id
where r.contact_email = sponsor_email and r.type = 'sponsor' and r.points = 33 and r.checked_in)
and exists (select 1 from public.registrations r join sessionize_guard_fixture f on f.event_id = r.event_id