From e3a065d15d8022288059ecfd78529607e562785d Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Mon, 13 Apr 2026 16:02:45 +0900 Subject: [PATCH] =?UTF-8?q?fix(memos):=20migration=EC=9D=84=20=EA=B0=9C?= =?UTF-8?q?=EB=B3=84=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20?= =?UTF-8?q?(asyncpg=20multi-statement=20=EB=AF=B8=EC=A7=80=EC=9B=90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit asyncpg prepared statement가 multi-command를 지원하지 않아 시작 실패. 105 단일 파일을 105-112 개별 statement로 분리. Co-Authored-By: Claude Opus 4.6 (1M context) --- migrations/105_memo_support.sql | 30 ++----------------- migrations/106_memo_file_path_nullable.sql | 2 ++ .../107_memo_file_path_partial_unique.sql | 2 ++ .../108_memo_file_path_partial_unique_idx.sql | 2 ++ migrations/109_memo_columns.sql | 3 ++ migrations/110_memo_pinned.sql | 2 ++ migrations/111_memo_ask_includable.sql | 2 ++ migrations/112_memo_notes_index.sql | 2 ++ 8 files changed, 17 insertions(+), 28 deletions(-) create mode 100644 migrations/106_memo_file_path_nullable.sql create mode 100644 migrations/107_memo_file_path_partial_unique.sql create mode 100644 migrations/108_memo_file_path_partial_unique_idx.sql create mode 100644 migrations/109_memo_columns.sql create mode 100644 migrations/110_memo_pinned.sql create mode 100644 migrations/111_memo_ask_includable.sql create mode 100644 migrations/112_memo_notes_index.sql diff --git a/migrations/105_memo_support.sql b/migrations/105_memo_support.sql index 3e1da89..8f54ff4 100644 --- a/migrations/105_memo_support.sql +++ b/migrations/105_memo_support.sql @@ -1,28 +1,2 @@ --- 105: 메모(note) 기능 지원 --- 메모 = file_type='note'인 document (파일 없는 문서) --- file_hash는 note에서 content SHA-256 (파일 해시가 아닌 본문 버전 해시) - --- source_channel enum에 'memo' 추가 (유입 경로: 내장 메모 UI) -ALTER TYPE source_channel ADD VALUE IF NOT EXISTS 'memo'; - --- file_path: NOT NULL 제거 (메모는 파일 없음) -ALTER TABLE documents ALTER COLUMN file_path DROP NOT NULL; - --- file_path: 기존 UNIQUE → partial unique (NULL 허용, 값 있으면 유니크) -DROP INDEX IF EXISTS documents_file_path_key; -CREATE UNIQUE INDEX IF NOT EXISTS uq_documents_file_path - ON documents(file_path) WHERE file_path IS NOT NULL; - --- user_tags: 사용자 수동 태그 (ai_tags와 분리, list[str]) -ALTER TABLE documents ADD COLUMN IF NOT EXISTS user_tags JSONB DEFAULT '[]'::jsonb; - --- pinned: 메모 핀 고정 -ALTER TABLE documents ADD COLUMN IF NOT EXISTS pinned BOOLEAN DEFAULT false; - --- ask_includable: /ask 합성 포함 여부 (false면 검색은 되지만 /ask evidence에서 제외) -ALTER TABLE documents ADD COLUMN IF NOT EXISTS ask_includable BOOLEAN DEFAULT true; - --- 메모 목록 최적화 인덱스 (핀 우선 + 최신순) -CREATE INDEX IF NOT EXISTS idx_documents_notes - ON documents(pinned DESC, created_at DESC) - WHERE file_type = 'note' AND deleted_at IS NULL; +-- 105: source_channel enum에 'memo' 추가 (메모 유입 경로) +ALTER TYPE source_channel ADD VALUE IF NOT EXISTS 'memo' diff --git a/migrations/106_memo_file_path_nullable.sql b/migrations/106_memo_file_path_nullable.sql new file mode 100644 index 0000000..064e078 --- /dev/null +++ b/migrations/106_memo_file_path_nullable.sql @@ -0,0 +1,2 @@ +-- 106: file_path NOT NULL 제거 (메모는 파일 없는 문서) +ALTER TABLE documents ALTER COLUMN file_path DROP NOT NULL diff --git a/migrations/107_memo_file_path_partial_unique.sql b/migrations/107_memo_file_path_partial_unique.sql new file mode 100644 index 0000000..4d41b62 --- /dev/null +++ b/migrations/107_memo_file_path_partial_unique.sql @@ -0,0 +1,2 @@ +-- 107: file_path UNIQUE → partial unique (NULL 허용, 값 있으면 유니크) +DROP INDEX IF EXISTS documents_file_path_key diff --git a/migrations/108_memo_file_path_partial_unique_idx.sql b/migrations/108_memo_file_path_partial_unique_idx.sql new file mode 100644 index 0000000..12d2d07 --- /dev/null +++ b/migrations/108_memo_file_path_partial_unique_idx.sql @@ -0,0 +1,2 @@ +-- 108: file_path partial unique 인덱스 생성 +CREATE UNIQUE INDEX IF NOT EXISTS uq_documents_file_path ON documents(file_path) WHERE file_path IS NOT NULL diff --git a/migrations/109_memo_columns.sql b/migrations/109_memo_columns.sql new file mode 100644 index 0000000..e455419 --- /dev/null +++ b/migrations/109_memo_columns.sql @@ -0,0 +1,3 @@ +-- 109: 메모 지원 컬럼 추가 (user_tags, pinned, ask_includable) +-- file_hash는 note에서 content SHA-256 (파일 해시가 아닌 본문 버전 해시) +ALTER TABLE documents ADD COLUMN IF NOT EXISTS user_tags JSONB DEFAULT '[]'::jsonb diff --git a/migrations/110_memo_pinned.sql b/migrations/110_memo_pinned.sql new file mode 100644 index 0000000..c6b1cce --- /dev/null +++ b/migrations/110_memo_pinned.sql @@ -0,0 +1,2 @@ +-- 110: 메모 핀 고정 컬럼 +ALTER TABLE documents ADD COLUMN IF NOT EXISTS pinned BOOLEAN DEFAULT false diff --git a/migrations/111_memo_ask_includable.sql b/migrations/111_memo_ask_includable.sql new file mode 100644 index 0000000..52ac055 --- /dev/null +++ b/migrations/111_memo_ask_includable.sql @@ -0,0 +1,2 @@ +-- 111: /ask 합성 포함 여부 (false면 검색은 되지만 /ask evidence에서 제외) +ALTER TABLE documents ADD COLUMN IF NOT EXISTS ask_includable BOOLEAN DEFAULT true diff --git a/migrations/112_memo_notes_index.sql b/migrations/112_memo_notes_index.sql new file mode 100644 index 0000000..9cf1a45 --- /dev/null +++ b/migrations/112_memo_notes_index.sql @@ -0,0 +1,2 @@ +-- 112: 메모 목록 최적화 인덱스 (핀 우선 + 최신순) +CREATE INDEX IF NOT EXISTS idx_documents_notes ON documents(pinned DESC, created_at DESC) WHERE file_type = 'note' AND deleted_at IS NULL