40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
|
|
"""article_scores geo: per-article proximate location for /api/news/blips
|
||
|
|
|
||
|
|
Revision ID: 014_article_scores_geo
|
||
|
|
Revises: 013_article_scores_duplicate_of
|
||
|
|
Create Date: 2026-11-19
|
||
|
|
|
||
|
|
Additive nullable columns on article_scores (every graded article keeps
|
||
|
|
its grading row; geo rides along when derivable). Partial bbox index for
|
||
|
|
the blips endpoint's bbox= filter. Idempotent DDL mirrors the summarizer's
|
||
|
|
ensure_tables so either start order is safe.
|
||
|
|
"""
|
||
|
|
|
||
|
|
from alembic import op
|
||
|
|
|
||
|
|
revision = "014_article_scores_geo"
|
||
|
|
down_revision = "013_article_scores_duplicate_of"
|
||
|
|
branch_labels = None
|
||
|
|
depends_on = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
op.execute("ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS location_name TEXT")
|
||
|
|
op.execute("ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS lat DOUBLE PRECISION")
|
||
|
|
op.execute("ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS lon DOUBLE PRECISION")
|
||
|
|
op.execute(
|
||
|
|
"ALTER TABLE article_scores ADD COLUMN IF NOT EXISTS location_confidence TEXT"
|
||
|
|
)
|
||
|
|
op.execute(
|
||
|
|
"CREATE INDEX IF NOT EXISTS ix_article_scores_geo_bbox "
|
||
|
|
"ON article_scores (lon, lat) "
|
||
|
|
"WHERE lat IS NOT NULL AND lon IS NOT NULL"
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
op.execute("DROP INDEX IF EXISTS ix_article_scores_geo_bbox")
|
||
|
|
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS location_confidence")
|
||
|
|
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS lon")
|
||
|
|
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS lat")
|
||
|
|
op.execute("ALTER TABLE article_scores DROP COLUMN IF EXISTS location_name")
|