create table if not exists public.challenge_retry_requests ( request_id uuid primary key default gen_random_uuid(), submission_id text not null unique references public.submissions(submission_id) on delete cascade, round_id uuid not null references public.challenge_rounds(round_id) on delete cascade, course_id text not null, auth_provider text not null, provider_user_id text not null, student_name text not null, reason text not null default '' check (length(reason) <= 1000), requested_at timestamptz not null default now(), status text not null default 'pending' check (status in ('pending', 'approved', 'denied')), lecturer_response text, reviewed_at timestamptz, reviewed_by text ); create index if not exists challenge_retry_requests_round_idx on public.challenge_retry_requests (course_id, round_id, status, requested_at desc); alter table public.challenge_retry_requests enable row level security; revoke all on table public.challenge_retry_requests from public, anon, authenticated; grant select, insert, update on table public.challenge_retry_requests to service_role;