fix(news): per-bill URL dedup + lazy re-fetch on bill detail load
- Drop global unique constraint on news_articles.url; replace with (bill_id, url) so the same article can appear for multiple bills - news_fetcher dedup now scoped to bill_id instead of global URL - Bill detail endpoint triggers a background news fetch when no articles are stored, so gnews articles surface on next load Migration 0009. Co-Authored-By: Jack Levy
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, Float, DateTime, ForeignKey, Index
|
||||
from sqlalchemy import Column, Integer, String, Text, Float, DateTime, ForeignKey, Index, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
@@ -12,7 +12,7 @@ class NewsArticle(Base):
|
||||
bill_id = Column(String, ForeignKey("bills.bill_id", ondelete="CASCADE"), nullable=False)
|
||||
source = Column(String(200))
|
||||
headline = Column(Text)
|
||||
url = Column(String, unique=True)
|
||||
url = Column(String)
|
||||
published_at = Column(DateTime(timezone=True))
|
||||
relevance_score = Column(Float, default=0.0)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
@@ -20,6 +20,7 @@ class NewsArticle(Base):
|
||||
bill = relationship("Bill", back_populates="news_articles")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("bill_id", "url", name="uq_news_articles_bill_url"),
|
||||
Index("ix_news_articles_bill_id", "bill_id"),
|
||||
Index("ix_news_articles_published_at", "published_at"),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user