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;