Files
hyungi_document_server/migrations/291_study_memo_card_jobs.sql
hyungi 0a7402b327 feat(study): 공부 암기노트 Phase 1 — card_extract 추출 파이프라인 (순수 additive)
study_memo_cards 추출 파이프라인 + 버전키 폴러 + needs_review 컬럼. 운영 SR 코드(session_finalize/quiz_selection) 무수정.

- migrations 287~298: study_memo_cards/_evidence/_jobs/_progress(P1 휴면)·study_reminders·study_topics.focused_at·study_questions needs_review 3컬럼. dedup PARTIAL UNIQUE(deleted_at IS NULL).
- 워커: in-process RAG gather → MLX {cards} → 카드 가드(정량=evidence 원문 등장·cue/cloze 누출·dedup) → supersede 구버전 retire → append. 별 consumer 로 기존 study_queue 격리.
- 폴러 study_card_enqueue: 버전키 NOT EXISTS(source_version) 멱등 + ai_explanation_generated_at NOT NULL 가드 + per-poll LIMIT(thundering-herd).
- 검증: 실 prod 스키마 덤프 위 12 마이그 적용 OK + dedup/supersede/active-unique 기능 7/7 PASS + 정규화 util 15/15.

plan: PKM plans/2026-06-05-study-memo-card-p1-plan.html

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 21:33:12 +09:00

30 lines
1.4 KiB
SQL

-- 291_study_memo_card_jobs.sql
-- card_extract 비동기 작업 큐 (231_study_question_jobs.sql 복제 + 다형 소스).
-- 라이프사이클: pending -> processing -> completed | failed | skipped
-- error_code 권장값: parse_fail / llm_timeout / unknown (재시도 대상),
-- all_dropped (0장 생성, completed 로 종결해 재추출 차단),
-- no_ready_explanation (skipped, 비재시도).
-- source_question_id 직접 FK 대신 source_kind/source_id 다형 참조 (question|subject_note|document).
-- source_version = 추출 대상 study_questions.ai_explanation_generated_at (버전 멱등키) —
-- 폴러의 NOT EXISTS(... AND source_version=현재버전) 가 같은 버전 재추출을 차단.
CREATE TABLE IF NOT EXISTS study_memo_card_jobs (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
source_kind VARCHAR(40) NOT NULL,
source_id BIGINT NOT NULL,
source_version TIMESTAMPTZ,
kind VARCHAR(40) NOT NULL,
status VARCHAR(20) NOT NULL DEFAULT 'pending',
attempts SMALLINT NOT NULL DEFAULT 0,
max_attempts SMALLINT NOT NULL DEFAULT 2,
error_code VARCHAR(40),
error_message TEXT,
payload JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
started_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ
);