34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
|
|
"""Store source sector detail alongside immutable publication daily inputs."""
|
||
|
|
|
||
|
|
from collections.abc import Sequence
|
||
|
|
|
||
|
|
import sqlalchemy as sa
|
||
|
|
from alembic import op
|
||
|
|
|
||
|
|
revision: str = "0009_radar_sector_detail"
|
||
|
|
down_revision: str | None = "0008_radar_detail"
|
||
|
|
branch_labels: str | Sequence[str] | None = None
|
||
|
|
depends_on: str | Sequence[str] | None = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
"""Keep all previous rows readable with nullable provider detail."""
|
||
|
|
op.add_column(
|
||
|
|
"sector_radar_daily_aggregate", sa.Column("pct_change", sa.Numeric(), nullable=True)
|
||
|
|
)
|
||
|
|
op.add_column(
|
||
|
|
"sector_radar_daily_aggregate", sa.Column("leading_code", sa.Text(), nullable=True)
|
||
|
|
)
|
||
|
|
op.create_check_constraint(
|
||
|
|
"ck_radar_sector_pct_change_finite",
|
||
|
|
"sector_radar_daily_aggregate",
|
||
|
|
"pct_change IS NULL OR pct_change NOT IN "
|
||
|
|
"('NaN'::numeric, 'Infinity'::numeric, '-Infinity'::numeric)",
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
"""Remove only the nullable projection; original provider snapshots remain intact."""
|
||
|
|
op.drop_column("sector_radar_daily_aggregate", "leading_code")
|
||
|
|
op.drop_column("sector_radar_daily_aggregate", "pct_change")
|