fix(briefing): split migration into 4 single-statement files
asyncpg 의 prepared statement 가 multi-statement 불허. Phase 4 101 SQL 은 2026-04-08 적용 당시엔 통과했지만 현재 asyncpg/sqlalchemy 버전에서 fail. 255_morning_briefings_table.sql CREATE TABLE morning_briefings 256_morning_briefings_idx.sql CREATE INDEX (briefing_date) 257_briefing_topics_table.sql CREATE TABLE briefing_topics + UNIQUE 258_briefing_topics_idx.sql CREATE INDEX (briefing_id, topic_rank)
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
-- 야간 수집 뉴스 브리핑 (Morning Briefing)
|
||||
-- 매일 KST 자정~05:00 사이 수집된 뉴스를 topic-country 비교 분석 1페이지 카드.
|
||||
-- 트리거: 05:10 KST APScheduler cron (PR-3 에서 등록). Phase 4 와 axis 반대 (topic-first).
|
||||
-- 코드/로직/테이블 모두 Phase 4 와 분리. 공통 알고리즘만 services/clustering_common 공유.
|
||||
|
||||
CREATE TABLE morning_briefings (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
briefing_date DATE NOT NULL,
|
||||
window_start TIMESTAMPTZ NOT NULL,
|
||||
window_end TIMESTAMPTZ NOT NULL,
|
||||
decay_lambda DOUBLE PRECISION NOT NULL,
|
||||
total_articles INTEGER NOT NULL DEFAULT 0,
|
||||
total_countries INTEGER NOT NULL DEFAULT 0,
|
||||
total_topics INTEGER NOT NULL DEFAULT 0,
|
||||
generation_ms INTEGER,
|
||||
llm_calls INTEGER NOT NULL DEFAULT 0,
|
||||
llm_failures INTEGER NOT NULL DEFAULT 0,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'success',
|
||||
headline_oneliner TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (briefing_date)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_morning_briefings_date ON morning_briefings (briefing_date DESC);
|
||||
|
||||
CREATE TABLE briefing_topics (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
briefing_id BIGINT NOT NULL REFERENCES morning_briefings(id) ON DELETE CASCADE,
|
||||
topic_rank INTEGER NOT NULL,
|
||||
topic_label VARCHAR(120) NOT NULL,
|
||||
headline TEXT NOT NULL,
|
||||
country_perspectives JSONB NOT NULL DEFAULT '[]',
|
||||
divergences JSONB NOT NULL DEFAULT '[]',
|
||||
convergences JSONB NOT NULL DEFAULT '[]',
|
||||
key_quotes JSONB NOT NULL DEFAULT '[]',
|
||||
historical_article_ids JSONB,
|
||||
historical_context TEXT,
|
||||
historical_window_days INTEGER,
|
||||
cluster_members JSONB NOT NULL DEFAULT '[]',
|
||||
article_count INTEGER NOT NULL,
|
||||
country_count INTEGER NOT NULL,
|
||||
importance_score DOUBLE PRECISION NOT NULL,
|
||||
raw_weight_sum DOUBLE PRECISION NOT NULL,
|
||||
llm_model VARCHAR(100),
|
||||
llm_fallback_used BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (briefing_id, topic_rank)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_briefing_topics_briefing_rank ON briefing_topics (briefing_id, topic_rank);
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Morning Briefing 부모 테이블 (일일 1행, briefing_date UNIQUE).
|
||||
-- asyncpg prepared statement 가 multi-statement 불허라 인덱스 + 자식 테이블은 별 migration.
|
||||
CREATE TABLE morning_briefings (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
briefing_date DATE NOT NULL,
|
||||
window_start TIMESTAMPTZ NOT NULL,
|
||||
window_end TIMESTAMPTZ NOT NULL,
|
||||
decay_lambda DOUBLE PRECISION NOT NULL,
|
||||
total_articles INTEGER NOT NULL DEFAULT 0,
|
||||
total_countries INTEGER NOT NULL DEFAULT 0,
|
||||
total_topics INTEGER NOT NULL DEFAULT 0,
|
||||
generation_ms INTEGER,
|
||||
llm_calls INTEGER NOT NULL DEFAULT 0,
|
||||
llm_failures INTEGER NOT NULL DEFAULT 0,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'success',
|
||||
headline_oneliner TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (briefing_date)
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
CREATE INDEX idx_morning_briefings_date ON morning_briefings (briefing_date DESC)
|
||||
@@ -0,0 +1,26 @@
|
||||
-- Morning Briefing 자식 (topic_rank 순, UNIQUE briefing_id + topic_rank).
|
||||
-- country_perspectives/divergences/convergences/key_quotes JSONB (cap 은 application).
|
||||
-- historical_* 3 컬럼은 BRIEFING_HISTORICAL_ENABLED on 시만 채움 (nullable).
|
||||
CREATE TABLE briefing_topics (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
briefing_id BIGINT NOT NULL REFERENCES morning_briefings(id) ON DELETE CASCADE,
|
||||
topic_rank INTEGER NOT NULL,
|
||||
topic_label VARCHAR(120) NOT NULL,
|
||||
headline TEXT NOT NULL,
|
||||
country_perspectives JSONB NOT NULL DEFAULT '[]',
|
||||
divergences JSONB NOT NULL DEFAULT '[]',
|
||||
convergences JSONB NOT NULL DEFAULT '[]',
|
||||
key_quotes JSONB NOT NULL DEFAULT '[]',
|
||||
historical_article_ids JSONB,
|
||||
historical_context TEXT,
|
||||
historical_window_days INTEGER,
|
||||
cluster_members JSONB NOT NULL DEFAULT '[]',
|
||||
article_count INTEGER NOT NULL,
|
||||
country_count INTEGER NOT NULL,
|
||||
importance_score DOUBLE PRECISION NOT NULL,
|
||||
raw_weight_sum DOUBLE PRECISION NOT NULL,
|
||||
llm_model VARCHAR(100),
|
||||
llm_fallback_used BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
UNIQUE (briefing_id, topic_rank)
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
CREATE INDEX idx_briefing_topics_briefing_rank ON briefing_topics (briefing_id, topic_rank)
|
||||
Reference in New Issue
Block a user