"""MatchStats 新增 xG 追踪字段 Revision ID: 0009_match_stats_xg_fields Revises: 0008_raw_event_and_ingest_failure Create Date: 2026-09-17 架构审查报告 P1-4 实施: understat 允许纠正旧 xG 值。新增字段追踪 xG 具体来源和更新时间, 实现全量覆盖模式:当 understat 数据更新时覆盖旧值而非跳过。 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = '0009_match_stats_xg_fields' down_revision: Union[str, None] = '0008_raw_event_and_ingest_failure' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.add_column("match_stats", sa.Column("xg_source", sa.String(30), nullable=True)) op.add_column("match_stats", sa.Column("xg_updated_at", sa.DateTime(timezone=True), nullable=True)) op.add_column("match_stats", sa.Column("xg_source_record_id", sa.String(100), nullable=True)) op.create_index("ix_match_stats_xg_source", "match_stats", ["xg_source", "xg_updated_at"]) def downgrade() -> None: op.drop_index("ix_match_stats_xg_source", table_name="match_stats") op.drop_column("match_stats", "xg_source_record_id") op.drop_column("match_stats", "xg_updated_at") op.drop_column("match_stats", "xg_source")