fix(migrations): 143 asyncpg multi-statement 분리 #3

Merged
hyungi merged 1 commits from fix/migration-143-split into main 2026-04-23 15:46:35 +09:00
4 changed files with 38 additions and 21 deletions
+9 -21
View File
@@ -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;
@@ -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;
@@ -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);
@@ -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;