8fdea88676
plan: ~/.claude/plans/luminous-sprouting-hamster.md §1
- migrations/143_category.sql: doc_category enum (6 활성 + 3 유보) +
documents.category + documents.ai_suggestion JSONB + 2 idx.
- app/models/document.py: category (Enum, create_type=False), ai_suggestion (JSONB).
- app/prompts/classify.txt: document_type enum 에 7 실무 doctype 추가
(발주서/세금계산서/명세표/도면/증명서/계획서/시방서) + facet_doctype
필드 directive.
- config.yaml: document_types 에 7 항목 추가 (worker 검증 통과).
- app/workers/classify_worker.py: FACET_DOCTYPES / LIBRARY_SUGGESTION_DOCTYPES
상수, facet_doctype 파싱(기존값 미덮어씀), 발주서/세금계산서/명세표
감지 시 ai_suggestion={proposed_category=library, proposed_path=@library/
거래/{YYYY}/{doctype}, source_updated_at=doc.updated_at.isoformat(), ...}.
category / user_tags 자동 전이 금지 (suggestion-only).
- app/api/documents.py:
· DocumentResponse 에 category / ai_suggestion 노출
· GET /documents ?category=<cat> / ?has_suggestion / ?proposed_category
(category 지정 시 기본 news/memo 제외 해제 — §2 승인 UI 계약)
· GET /documents/library 를 Document.category=='library' 기반으로 재구현
(path subquery 는 user_tags 유지 — 분류 내부 서가 경로)
· POST /documents/{id}/accept-suggestion — FOR UPDATE + idempotent no-op +
dual 409 stale (payload source_updated_at / documents.updated_at) +
user_tags idempotent append
· DELETE /documents/{id}/suggestion — idempotent, stale 검사 없음
- scripts/backfill_category.py: dry-run / apply. 매핑(news/memo/@library/else)
+ 3-way 상대 검증 (all_rows==categorized, uncategorized==0,
cat_library==has_library_tag — 자동 전이 금지 정책 검증).
남은 DoD (원격 배포 후): docker compose up → migration 143 적용 → backfill
apply → smoke (drive_sync 발주서 업로드 suggestion 생성 / category 유지,
accept-suggestion idempotency + 409 stale 두 벡터, /documents?category=library
== /documents/library 건수 일치).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
986 B
SQL
31 lines
986 B
SQL
-- 143_category.sql
|
|
-- Document Server 통합 플랫폼 Section 1: category enum + ai_suggestion
|
|
-- plan: luminous-sprouting-hamster.md §1
|
|
--
|
|
-- doc_category enum (6 활성 + 3 유보):
|
|
-- document / library / news / memo / audio / video
|
|
-- mail / calendar / plex (유보)
|
|
--
|
|
-- ai_suggestion (JSONB): 승인 전 제안 payload
|
|
-- {
|
|
-- proposed_category, proposed_path, proposed_doctype,
|
|
-- confidence, source_updated_at, reason
|
|
-- }
|
|
-- 자동 전이 금지 — /accept-suggestion 승인 시에만 category / user_tags 변경
|
|
|
|
CREATE TYPE doc_category AS ENUM (
|
|
'document', 'library', 'news', 'memo', 'audio', 'video',
|
|
'mail', 'calendar', 'plex'
|
|
);
|
|
|
|
ALTER TABLE documents
|
|
ADD COLUMN IF NOT EXISTS category doc_category,
|
|
ADD COLUMN IF NOT EXISTS ai_suggestion JSONB;
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_documents_category
|
|
ON documents(category);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_documents_has_suggestion
|
|
ON documents(id)
|
|
WHERE ai_suggestion IS NOT NULL;
|