File size: 2,626 Bytes
8b26302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91592d2
8b26302
 
 
 
91592d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b26302
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
create table if not exists public.submissions (
    submission_id text primary key,
    submitted_at timestamptz not null,
    student_name text not null,
    auth_provider text,
    provider_user_id text,
    challenge_id text,
    repo_url text,
    target_file text,
    attempt_number integer not null default 1,
    hints_used integer not null default 0,
    llm_score integer,
    total_score integer,
    passed_tests integer,
    total_tests integer,
    submission_outcome text,
    review_report text,
    payload jsonb not null,
    created_at timestamptz not null default now()
);

alter table public.submissions
    add column if not exists review_report text;

update public.submissions
set review_report = concat_ws(
        E'\n\n',
        'SUBMISSION REVIEW: ' || submission_id,
        'Student: ' || coalesce(payload #>> '{student,name}', student_name),
        'Hugging Face: ' || coalesce(payload #>> '{student,provider_user_id}', '(not provided)'),
        'Challenge: ' || coalesce(payload #>> '{challenge,challenge_id}', challenge_id, '(not provided)'),
        'Repository: ' || coalesce(payload #>> '{challenge,repo_url}', repo_url, '(not provided)'),
        'What was the bug:' || E'\n' || coalesce(payload #>> '{challenge,bug_description}', '(not provided)'),
        'Challenge summary:' || E'\n' || coalesce(payload #>> '{challenge,challenge_summary}', '(not provided)'),
        'Buggy code given to the student:' || E'\n' || coalesce(payload #>> '{challenge,buggy_code}', '(not provided)'),
        'Student changes (diff):' || E'\n' || coalesce(payload #>> '{submission,student_diff}', '(not provided)'),
        'Expected fix:' || E'\n' || coalesce(payload #>> '{challenge,expected_fixed_code}', '(not provided)'),
        'Test results:' || E'\n' || coalesce(jsonb_pretty(payload -> 'tests'), '(not provided)'),
        'Scoring:' || E'\n' || coalesce(jsonb_pretty(payload -> 'scoring'), '(not provided)'),
        'Chat history:' || E'\n' || coalesce(jsonb_pretty(payload #> '{submission,chat_history}'), '(not provided)')
)
where review_report is null
    and payload is not null;

create index if not exists submissions_provider_user_id_idx
    on public.submissions (provider_user_id);
create index if not exists submissions_submitted_at_idx
    on public.submissions (submitted_at desc);
create index if not exists submissions_challenge_id_idx
    on public.submissions (challenge_id);

alter table public.submissions enable row level security;
revoke all on table public.submissions from anon, authenticated;
grant select, insert, update on table public.submissions to service_role;