fix(migrations): 143 asyncpg multi-statement 분리
asyncpg prepared statement 는 single-command 만 지원 (core/database.py exec_driver_sql 경로). §1 의 143_category.sql 이 4 statement (TYPE + ALTER + INDEX×2) 였어서 fastapi 부팅 시 asyncpg.PostgresSyntaxError "cannot insert multiple commands into a prepared statement" 로 실패 → 컨테이너 restart 루프. 143 을 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 (partial) DB 상태는 깨끗 (migration 143 이 부분 적용 안 됨 — asyncpg 가 batch 자체를 reject). schema_migrations 에 143 도 미기록이라 재실행 안전. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit was merged in pull request #3.
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user