fix(study): split migration 164 into 10 single-statement files (asyncpg)
asyncpg prepared statement 는 single-command 만 허용. 원래 한 파일이던 study_sessions 스키마(CREATE TABLE x2 + CREATE INDEX x8)를 143~146 분할 패턴 따라 10개로 분리. 164: CREATE TABLE study_sessions 165~169: study_sessions 인덱스 5개 (partial) 170: CREATE TABLE study_session_assets 171~173: study_session_assets 인덱스 3개 문제: cannot insert multiple commands into a prepared statement 원인: _run_migrations 가 conn.exec_driver_sql 로 단일 prepared statement 실행
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
-- 170_study_session_assets.sql (7/10)
|
||||
-- documents 의 스캔 교재 / 필기 PNG / 오디오 / 영상 / 자막을 study_sessions 에 연결하는 테이블.
|
||||
--
|
||||
-- 단일 *_document_id 컬럼 금지 — 한 세션에 여러 오디오/영상/스캔/필기 PNG 가능.
|
||||
-- documents 원본은 assets 와 별도 자원 — 본 테이블 cascade 는 study_sessions / documents 둘 중
|
||||
-- 어느 쪽이 사라지면 연결 행 정리 (orphan 방지).
|
||||
--
|
||||
-- UNIQUE (study_session_id, document_id, asset_type, role): POST /assets 의 409 근거.
|
||||
-- role 이 NULL 인 경우 NULL 끼리는 Postgres 기본대로 다른 값으로 취급 (의도된 동작).
|
||||
|
||||
CREATE TABLE IF NOT EXISTS study_session_assets (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
study_session_id BIGINT NOT NULL REFERENCES study_sessions(id) ON DELETE CASCADE,
|
||||
document_id BIGINT NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
|
||||
asset_type VARCHAR(30) NOT NULL,
|
||||
role VARCHAR(40),
|
||||
sort_order INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (study_session_id, document_id, asset_type, role)
|
||||
);
|
||||
Reference in New Issue
Block a user