-- 318_document_chunks_char_start.sql
-- 플랜 ds-outline-anchor-b5 (Path B, g1-t1): hier 절 → md_content 본문 점프용 offset 컬럼.
--
-- char_start = md_content 내 heading 라인 시작 offset, **UTF-16 code unit** 기준
--   (FE outlineAnchors.ts:64 `off += raw.length + 1` / MarkdownDoc.svelte:63 `out.slice(off)` 와 동일 단위).
-- NULL 허용 = (a) md_content 없음(legacy/news/Path A) (b) window-child(node_type='window') (c) preamble(title NULL).
--   → jump-target(비-window leaf OR %_split parent)만 NOT NULL 을 받는다(BY DESIGN, B1/B3 완료마커 기준).
--
-- 두 backfill 경로 공통 prereq:
--   - UPDATE-only path(g3-tU, hash_stable): 저장된 hier 행에 char_start 만 UPDATE (DELETE/CASCADE/재임베딩 0).
--   - re-decompose path(g3-t2, hash_changed): persist INSERT 시 char_start 동봉.
--
-- 멱등: ADD COLUMN IF NOT EXISTS + init_db version-skip + pg_advisory_xact_lock. BEGIN/COMMIT 금지(단일 statement).

ALTER TABLE document_chunks ADD COLUMN IF NOT EXISTS char_start INTEGER NULL;
