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:
Jack Levy
2026-03-01 00:43:10 -05:00
parent a66b5b4bcb
commit 50f93468db
4 changed files with 43 additions and 4 deletions

View File

@@ -0,0 +1,29 @@
"""fix news_articles url uniqueness to per-bill scope
Previously url was globally unique, meaning the same article could only
be stored for one bill. This changes it to (bill_id, url) unique so the
same article can appear in multiple bills' news panels.
Revision ID: 0009
Revises: 0008
Create Date: 2026-03-01
"""
import sqlalchemy as sa
from alembic import op
revision = "0009"
down_revision = "0008"
branch_labels = None
depends_on = None
def upgrade():
# Drop the old global unique constraint on url
op.drop_constraint("news_articles_url_key", "news_articles", type_="unique")
# Add per-bill unique constraint
op.create_unique_constraint("uq_news_articles_bill_url", "news_articles", ["bill_id", "url"])
def downgrade():
op.drop_constraint("uq_news_articles_bill_url", "news_articles", type_="unique")
op.create_unique_constraint("news_articles_url_key", "news_articles", ["url"])