4b7156061e
study_topic 워크스페이스에 4지선다 문제은행 자산 트랙 추가. 기사시험 필기
대비 시나리오 — 빠른 반복 입력 + 과목별 균등 추출 복습 + 정오답 누적.
데이터 모델 (migrations 186~190):
- study_questions: study_topic 1:N, soft delete, is_active 토글, correct_choice
SMALLINT CHECK 1~4
- study_question_attempts: 답 제출 1행 누적. study_question_id FK는 ON DELETE
RESTRICT (이력 보존 원칙 — hard delete 실수로 풀이 기록 소실 차단)
설계 원칙:
- 문제 삭제는 API 에서 soft delete only. attempts FK RESTRICT 로 DB 레벨도 보호
- correct_choice 변경 시 기존 attempts.is_correct 재계산 안 함 (시점 사실 보존)
- 복습 default = 과목별 target_per_subject(20) 무작위 균등 추출. 한 과목이
부족하면 가용한 만큼만
- wrong_only=true 정의 = 가장 최근 attempt 가 오답인 문제 (latest-wrong, ever-wrong 아님)
- 출제 응답에서 정답·해설 비공개. 답 제출 시점에만 노출
- subject/scope 강한 enum 미사용 (자유 텍스트, 자동완성은 후속)
API: /api/study-topics/{id}/questions, /review/questions, /api/study-questions/{id},
/attempt. 통합뷰(/study-topics/{id}) 응답에 sections.questions / stats.question_count
추가. 기존 question_set_count 는 후속 PR(회차/모의고사 묶음)용으로 보존.
프론트: /study/topics/[id]에 문제 섹션 + "새 문제"/"복습 시작" 진입.
/questions/new (저장 후 계속 입력 + sessionStorage persistent),
/questions/[qid]/edit (정답 변경 시 attempts 재계산 안 됨 안내 배너),
/review (시작 옵션 → 풀이 → 마지막 요약).
후속 PR 예정: 오답노트/취약 과목 리포트, AI 해설/클러스터링, spaced
repetition, 이미지 OCR 입력, CSV import, study_question_sets 묶음.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
25 lines
1.5 KiB
SQL
25 lines
1.5 KiB
SQL
-- 188_study_question_attempts.sql (3/5)
|
|
-- 복습모드에서 답 제출할 때마다 1행 누적. 통계·오답노트의 토대.
|
|
--
|
|
-- FK 정책 (이력 보존 원칙):
|
|
-- - study_question_id ON DELETE RESTRICT — 문제 삭제는 API 에서 soft delete 만 수행.
|
|
-- hard delete 실수로 풀이 이력이 사라지면 안 되기 때문에 DB 레벨에서도 막는다. CASCADE 금지.
|
|
-- - study_topic_id ON DELETE CASCADE — 토픽 삭제는 워크스페이스 전체 폐기 의미.
|
|
-- 단 PR-1 의 토픽 삭제도 soft delete 라 실 cascade 발생은 hard delete 시.
|
|
-- - user_id ON DELETE CASCADE — 사용자 탈퇴 정리.
|
|
--
|
|
-- correct_choice 컬럼은 attempt 시점 정답을 그대로 보존 — 문제 편집으로 정답 변경되어도
|
|
-- 기존 attempt 의 is_correct 는 재계산 안 함 (기록은 시점 사실).
|
|
-- selected_choice/correct_choice 모두 SMALLINT CHECK 1~4.
|
|
|
|
CREATE TABLE IF NOT EXISTS study_question_attempts (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
study_question_id BIGINT NOT NULL REFERENCES study_questions(id) ON DELETE RESTRICT,
|
|
study_topic_id BIGINT NOT NULL REFERENCES study_topics(id) ON DELETE CASCADE,
|
|
selected_choice SMALLINT NOT NULL CHECK (selected_choice BETWEEN 1 AND 4),
|
|
correct_choice SMALLINT NOT NULL CHECK (correct_choice BETWEEN 1 AND 4),
|
|
is_correct BOOLEAN NOT NULL,
|
|
answered_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|