7f93d6b0f5
- Introduced ActiveMoneyflowSource to fetch optional active-order flow, enhancing the sector radar's data capabilities. - Updated StockFactRecord and DailyAggregateRecord to include pct_change and active_buy_net_amount_yuan for improved financial insights. - Modified the build process to incorporate active moneyflow data without invalidating main rankings on failure. - Enhanced the HTTP API to return detailed sector history and metrics, including pct_change and active buy metrics for members. - Updated tests to validate the new functionality and ensure data integrity across various scenarios.
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")
|