feat(insta-lab): 발행 상태 컬럼 + set_slate_decision/list_recent_issued_topics
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,13 @@ def init_db() -> None:
|
||||
(cat, 1.0),
|
||||
)
|
||||
|
||||
# 발행 상태 컬럼 (idempotent ALTER) — 자율 발급 파이프라인
|
||||
cs_cols = [r[1] for r in conn.execute("PRAGMA table_info(card_slates)").fetchall()]
|
||||
if "published_at" not in cs_cols:
|
||||
conn.execute("ALTER TABLE card_slates ADD COLUMN published_at TEXT")
|
||||
if "decision_at" not in cs_cols:
|
||||
conn.execute("ALTER TABLE card_slates ADD COLUMN decision_at TEXT")
|
||||
|
||||
|
||||
# ── news_articles ────────────────────────────────────────────────
|
||||
def add_news_article(row: Dict[str, Any]) -> int:
|
||||
@@ -217,6 +224,39 @@ def update_slate_status(slate_id: int, status: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
def set_slate_decision(slate_id: int, decision: str) -> None:
|
||||
"""승인/반려 결정 기록. approved→published(+published_at), rejected→rejected.
|
||||
멱등: 이미 published면 published_at 유지."""
|
||||
now = "strftime('%Y-%m-%dT%H:%M:%fZ','now')"
|
||||
with _conn() as conn:
|
||||
if decision == "approved":
|
||||
conn.execute(
|
||||
f"UPDATE card_slates SET status='published', "
|
||||
f"published_at=COALESCE(published_at, {now}), decision_at={now} "
|
||||
f"WHERE id=?",
|
||||
(slate_id,),
|
||||
)
|
||||
elif decision == "rejected":
|
||||
conn.execute(
|
||||
f"UPDATE card_slates SET status='rejected', decision_at={now} WHERE id=?",
|
||||
(slate_id,),
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"invalid decision: {decision}")
|
||||
|
||||
|
||||
def list_recent_issued_topics(window_days: int = 14) -> List[Dict[str, Any]]:
|
||||
"""최근 window_days 내 published/rejected 슬레이트의 (keyword, category). dedup용."""
|
||||
with _conn() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT keyword, category FROM card_slates "
|
||||
"WHERE status IN ('published','rejected') "
|
||||
"AND COALESCE(published_at, decision_at) >= datetime('now', ?)",
|
||||
(f"-{int(window_days)} days",),
|
||||
).fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
def get_card_slate(slate_id: int) -> Optional[Dict[str, Any]]:
|
||||
with _conn() as conn:
|
||||
row = conn.execute("SELECT * FROM card_slates WHERE id=?", (slate_id,)).fetchone()
|
||||
|
||||
Reference in New Issue
Block a user