fix(migrations): R1 baseline 런타임 버그 3건 — init_db asyncpg 경로 (R1 fix)
★실제 init_db() 런타임 검증(psql migration_smoke 가 못 잡는 asyncpg 경로)에서 발견·수정:
1. baseline 덤프에 CREATE TABLE schema_migrations 포함 → init_db 가 IF NOT EXISTS 로 선-CREATE
후 baseline 이 재-CREATE 충돌. --exclude-table=schema_migrations 재덤프(init_db 가 소유).
2. baseline 은 multi-statement 인데 exec_driver_sql(asyncpg prepared)은 multi-statement 불허
('cannot insert multiple commands into a prepared statement'). raw asyncpg simple 프로토콜
execute() 로 적재(같은 connection = 트랜잭션 내).
3. 마이그 360(10 DROP)·361(DELETE+CREATE)이 multi-statement → init_db 적용 실패. 360=콤마구분
단일 DROP, 361=단일 CREATE UNIQUE INDEX(prod 중복0·fresh 빈테이블이라 dedup DELETE 불요).
★검증: scripts/ci/initdb_runtime_test.py 로 실제 init_db 2회 — 1st(fresh: baseline 262 스탬프 +
359/360/361 적용, documents·purge_col·cand_drop·attempt_unique 전부 확인), 2nd(멱등 skip) PASS.
psql migration_smoke 도 PASS 유지.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
-- 360: Phase 2A 임베딩 후보 cand 섀도 테이블 제거 (R13).
|
||||
-- Phase 2A no-go 종결(2026-06-12, 후보 전부 -0.03~-0.04) + phase2a_cand_backfill 워커
|
||||
-- dormant. retrieval_service.CANDIDATE_BACKEND_MAP / api.search allowed 슬러그 선제거 후 DROP.
|
||||
-- Phase 2A no-go 종결(2026-06-12, 후보 전부 -0.03~-0.04) + phase2a_cand_backfill 워커 dormant.
|
||||
-- retrieval_service.CANDIDATE_BACKEND_MAP / api.search allowed 슬러그 선제거 후 DROP.
|
||||
-- ★single statement(콤마 구분) — init_db 의 exec_driver_sql(asyncpg)은 multi-statement 불허.
|
||||
-- IF EXISTS — me5/snowflake 는 ad-hoc 생성분이라 환경별 존재 여부 다를 수 있음(멱등).
|
||||
DROP TABLE IF EXISTS document_chunks_cand_me5_large_inst;
|
||||
DROP TABLE IF EXISTS documents_cand_me5_large_inst;
|
||||
DROP TABLE IF EXISTS document_chunks_cand_snowflake_l_v2;
|
||||
DROP TABLE IF EXISTS documents_cand_snowflake_l_v2;
|
||||
DROP TABLE IF EXISTS document_chunks_cand_qwen06;
|
||||
DROP TABLE IF EXISTS documents_cand_qwen06;
|
||||
DROP TABLE IF EXISTS document_chunks_cand_qwen4;
|
||||
DROP TABLE IF EXISTS documents_cand_qwen4;
|
||||
DROP TABLE IF EXISTS document_chunks_cand_qwen4m;
|
||||
DROP TABLE IF EXISTS documents_cand_qwen4m;
|
||||
DROP TABLE IF EXISTS
|
||||
document_chunks_cand_me5_large_inst, documents_cand_me5_large_inst,
|
||||
document_chunks_cand_snowflake_l_v2, documents_cand_snowflake_l_v2,
|
||||
document_chunks_cand_qwen06, documents_cand_qwen06,
|
||||
document_chunks_cand_qwen4, documents_cand_qwen4,
|
||||
document_chunks_cand_qwen4m, documents_cand_qwen4m;
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
-- 361: quiz 세션 내 같은 문제 이중 attempt 방지 partial UNIQUE (R9).
|
||||
-- submit_attempt 의 FOR UPDATE 행잠금이 1차 방어이고, 이 제약은 DB 레벨 belt-and-suspenders
|
||||
-- (모바일 더블탭/재시도가 어떤 경로로든 이중 INSERT 에 도달해도 차단). prod 실측 중복 0 건
|
||||
-- (SELECT ... GROUP BY HAVING count>1 = 0) — dedup DELETE 는 멱등 precaution, UNIQUE 는 안전.
|
||||
-- quiz_session_id IS NULL(세션 외 직접 입력)은 대상 아님 → partial index.
|
||||
DELETE FROM study_question_attempts a USING study_question_attempts b
|
||||
WHERE a.quiz_session_id IS NOT NULL
|
||||
AND a.quiz_session_id = b.quiz_session_id
|
||||
AND a.study_question_id = b.study_question_id
|
||||
AND a.id > b.id;
|
||||
|
||||
-- submit_attempt 의 FOR UPDATE 행잠금이 1차 방어, 이 제약은 DB 레벨 belt-and-suspenders.
|
||||
-- prod 실측 중복 0 (GROUP BY (quiz_session_id, study_question_id) HAVING count>1 = 0) + fresh DB
|
||||
-- 빈 테이블이라 dedup DELETE 불요 → ★single statement(init_db exec_driver_sql 은 multi-statement
|
||||
-- 불허). 혹시 중복이 생긴 환경이면 이 마이그가 실패하므로(IntegrityError) 수동 dedup 후 재적용.
|
||||
-- quiz_session_id IS NULL(세션 외 직접 입력)은 비대상 → partial index.
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_attempt_session_question
|
||||
ON study_question_attempts (quiz_session_id, study_question_id)
|
||||
WHERE quiz_session_id IS NOT NULL;
|
||||
|
||||
@@ -1765,17 +1765,6 @@ CREATE SEQUENCE public.processing_queue_id_seq
|
||||
ALTER SEQUENCE public.processing_queue_id_seq OWNED BY public.processing_queue.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.schema_migrations (
|
||||
version integer NOT NULL,
|
||||
name text NOT NULL,
|
||||
applied_at timestamp with time zone DEFAULT now()
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: search_failure_logs; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@@ -3447,14 +3436,6 @@ ALTER TABLE ONLY public.processing_queue
|
||||
ADD CONSTRAINT processing_queue_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.schema_migrations
|
||||
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
|
||||
|
||||
|
||||
--
|
||||
-- Name: search_failure_logs search_failure_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user