From aceb54e586098a599e98a7aa7e27375ab3e6b078 Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Thu, 23 Apr 2026 15:46:00 +0900 Subject: [PATCH] =?UTF-8?q?fix(migrations):=20143=20asyncpg=20multi-statem?= =?UTF-8?q?ent=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- migrations/143_category.sql | 30 ++++++------------- migrations/144_documents_category_columns.sql | 14 +++++++++ migrations/145_documents_category_idx.sql | 6 ++++ .../146_documents_has_suggestion_idx.sql | 9 ++++++ 4 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 migrations/144_documents_category_columns.sql create mode 100644 migrations/145_documents_category_idx.sql create mode 100644 migrations/146_documents_has_suggestion_idx.sql 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;