diff --git a/migrations/143_category.sql b/migrations/143_category.sql index cedb3b8..4cf6a76 100644 --- a/migrations/143_category.sql +++ b/migrations/143_category.sql @@ -1,30 +1,18 @@ -- 143_category.sql --- Document Server 통합 플랫폼 Section 1: category enum + ai_suggestion +-- Document Server 통합 플랫폼 Section 1: doc_category enum 정의 (1/4) -- plan: luminous-sprouting-hamster.md §1 -- --- doc_category enum (6 활성 + 3 유보): --- document / library / news / memo / audio / video --- mail / calendar / plex (유보) +-- asyncpg prepared statement 는 single-command 만 허용. +-- 원래 한 파일이던 §1 스키마 변경을 4개로 분리: +-- 143: CREATE TYPE doc_category +-- 144: ALTER TABLE documents ADD category / ai_suggestion +-- 145: CREATE INDEX idx_documents_category +-- 146: CREATE INDEX idx_documents_has_suggestion -- --- ai_suggestion (JSONB): 승인 전 제안 payload --- { --- proposed_category, proposed_path, proposed_doctype, --- confidence, source_updated_at, reason --- } --- 자동 전이 금지 — /accept-suggestion 승인 시에만 category / user_tags 변경 +-- 6 활성: document / library / news / memo / audio / video +-- 3 유보: mail / calendar / plex 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; diff --git a/migrations/144_documents_category_columns.sql b/migrations/144_documents_category_columns.sql new file mode 100644 index 0000000..476a902 --- /dev/null +++ b/migrations/144_documents_category_columns.sql @@ -0,0 +1,14 @@ +-- 144_documents_category_columns.sql +-- Section 1: documents 에 category / ai_suggestion 컬럼 추가 (2/4) +-- plan: luminous-sprouting-hamster.md §1 +-- +-- ai_suggestion 구조: +-- { +-- proposed_category, proposed_path, proposed_doctype, +-- confidence, source_updated_at, reason +-- } +-- 자동 전이 금지 — /accept-suggestion 승인 시에만 category / user_tags 변경 + +ALTER TABLE documents + ADD COLUMN IF NOT EXISTS category doc_category, + ADD COLUMN IF NOT EXISTS ai_suggestion JSONB; diff --git a/migrations/145_documents_category_idx.sql b/migrations/145_documents_category_idx.sql new file mode 100644 index 0000000..58c0ea7 --- /dev/null +++ b/migrations/145_documents_category_idx.sql @@ -0,0 +1,6 @@ +-- 145_documents_category_idx.sql +-- Section 1: category 필터 인덱스 (3/4) +-- plan: luminous-sprouting-hamster.md §1 + +CREATE INDEX IF NOT EXISTS idx_documents_category + ON documents(category); diff --git a/migrations/146_documents_has_suggestion_idx.sql b/migrations/146_documents_has_suggestion_idx.sql new file mode 100644 index 0000000..82d1a3f --- /dev/null +++ b/migrations/146_documents_has_suggestion_idx.sql @@ -0,0 +1,9 @@ +-- 146_documents_has_suggestion_idx.sql +-- Section 1: 승인 대기 제안 partial index (4/4) +-- plan: luminous-sprouting-hamster.md §1 +-- +-- 승인 UI 가 hit 하는 SELECT ... WHERE ai_suggestion IS NOT NULL 용 partial idx. + +CREATE INDEX IF NOT EXISTS idx_documents_has_suggestion + ON documents(id) + WHERE ai_suggestion IS NOT NULL;