Files
hyungi_document_server/migrations/255_morning_briefings.sql
T
Hyungi Ahn 4aed9c6173 fix(briefing): simplify migration SQL (remove unicode, ::jsonb cast)
asyncpg 'cannot insert multiple commands into a prepared statement' 회피.
가설: 한국어 코멘트의 special char (lambda/arrow) + '::jsonb' cast 가 asyncpg
prepare 에서 multi-statement 오인. Phase 4 101 SQL 패턴과 정확히 맞춤 — JSONB
column 이라 default literal 은 자동 cast.
2026-05-12 13:02:16 +09:00

51 lines
2.3 KiB
SQL

-- 야간 수집 뉴스 브리핑 (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);