feat: add training case engine M1 persistence layer
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
create table if not exists training_cases (
|
||||
id bigserial primary key,
|
||||
instrument_id bigint not null references instruments(id),
|
||||
timeframe text not null,
|
||||
case_type text not null,
|
||||
skill_tag text not null,
|
||||
chapter_ref text,
|
||||
source_event_type text,
|
||||
source_event_id bigint,
|
||||
source_event_refs jsonb not null default '[]'::jsonb,
|
||||
start_ts timestamptz not null,
|
||||
decision_ts timestamptz not null,
|
||||
end_ts timestamptz not null,
|
||||
difficulty text not null default 'medium',
|
||||
answer_key jsonb not null default '{}'::jsonb,
|
||||
status text not null default 'draft',
|
||||
meta jsonb not null default '{}'::jsonb,
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now(),
|
||||
check (start_ts <= decision_ts),
|
||||
check (decision_ts <= end_ts)
|
||||
);
|
||||
|
||||
create index if not exists idx_training_cases_instr_tf_decision_desc
|
||||
on training_cases (instrument_id, timeframe, decision_ts desc);
|
||||
|
||||
create index if not exists idx_training_cases_skill_status_created_desc
|
||||
on training_cases (skill_tag, status, created_at desc);
|
||||
|
||||
create index if not exists idx_training_cases_type_status_created_desc
|
||||
on training_cases (case_type, status, created_at desc);
|
||||
|
||||
create table if not exists training_case_tasks (
|
||||
id bigserial primary key,
|
||||
case_id bigint not null references training_cases(id) on delete cascade,
|
||||
task_type text not null,
|
||||
skill_tag text not null,
|
||||
prompt text not null,
|
||||
required_annotation_types jsonb not null default '[]'::jsonb,
|
||||
max_score numeric(8,2) not null default 0,
|
||||
sort_order integer not null default 0,
|
||||
status text not null default 'active',
|
||||
meta jsonb not null default '{}'::jsonb,
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create index if not exists idx_training_case_tasks_case_sort
|
||||
on training_case_tasks (case_id, sort_order, id);
|
||||
|
||||
create index if not exists idx_training_case_tasks_skill_type
|
||||
on training_case_tasks (skill_tag, task_type);
|
||||
|
||||
create table if not exists training_attempts (
|
||||
id bigserial primary key,
|
||||
case_id bigint not null references training_cases(id),
|
||||
user_id text not null default 'local',
|
||||
status text not null default 'started',
|
||||
current_frame_index integer not null default 0,
|
||||
started_at timestamptz not null default now(),
|
||||
submitted_at timestamptz,
|
||||
total_score numeric(8,2),
|
||||
meta jsonb not null default '{}'::jsonb,
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create index if not exists idx_training_attempts_user_status_created_desc
|
||||
on training_attempts (user_id, status, created_at desc);
|
||||
|
||||
create index if not exists idx_training_attempts_case_user_created_desc
|
||||
on training_attempts (case_id, user_id, created_at desc);
|
||||
|
||||
create table if not exists training_annotations (
|
||||
id bigserial primary key,
|
||||
attempt_id bigint not null references training_attempts(id) on delete cascade,
|
||||
task_id bigint references training_case_tasks(id),
|
||||
user_id text not null default 'local',
|
||||
annotation_type text not null,
|
||||
payload jsonb not null default '{}'::jsonb,
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create index if not exists idx_training_annotations_attempt_type_created
|
||||
on training_annotations (attempt_id, annotation_type, created_at);
|
||||
|
||||
create table if not exists training_scores (
|
||||
id bigserial primary key,
|
||||
attempt_id bigint not null references training_attempts(id) on delete cascade,
|
||||
task_id bigint references training_case_tasks(id),
|
||||
user_id text not null default 'local',
|
||||
category text not null,
|
||||
score numeric(8,2) not null,
|
||||
max_score numeric(8,2) not null,
|
||||
feedback jsonb not null default '{}'::jsonb,
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now()
|
||||
);
|
||||
|
||||
create index if not exists idx_training_scores_attempt_category
|
||||
on training_scores (attempt_id, category);
|
||||
|
||||
create table if not exists training_progress (
|
||||
id bigserial primary key,
|
||||
user_id text not null default 'local',
|
||||
skill_tag text not null,
|
||||
attempt_count integer not null default 0,
|
||||
avg_score numeric(8,4),
|
||||
last_attempt_at timestamptz,
|
||||
weakness_tags jsonb not null default '[]'::jsonb,
|
||||
meta jsonb not null default '{}'::jsonb,
|
||||
created_at timestamptz not null default now(),
|
||||
updated_at timestamptz not null default now(),
|
||||
unique (user_id, skill_tag)
|
||||
);
|
||||
|
||||
create index if not exists idx_training_progress_user_skill
|
||||
on training_progress (user_id, skill_tag);
|
||||
Reference in New Issue
Block a user