"""initial_tables Revision ID: 0001_initial Revises: Create Date: 2026-09-07 00:00:00.000000 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision: str = '0001_initial' down_revision: Union[str, None] = None branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: # ### commands auto generated by Alembic ### op.create_table('leagues', sa.Column('id', sa.Integer(), nullable=False), sa.Column('code', sa.String(length=20), nullable=False), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('country', sa.String(length=50), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('code') ) op.create_table('teams', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(length=120), nullable=False), sa.Column('name_zh', sa.String(length=60), nullable=True), sa.Column('team_type', sa.String(length=20), nullable=False), sa.Column('created_at', sa.DateTime(timezone=True), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') ) op.create_table('matches', sa.Column('id', sa.Integer(), nullable=False), sa.Column('league_id', sa.Integer(), nullable=False), sa.Column('season', sa.String(length=12), nullable=True), sa.Column('home_team_id', sa.Integer(), nullable=False), sa.Column('away_team_id', sa.Integer(), nullable=False), sa.Column('match_date', sa.DateTime(timezone=True), nullable=False), sa.Column('match_date_date', sa.Date(), nullable=False), sa.Column('match_status', sa.String(length=20), nullable=False), sa.Column('home_goals', sa.Integer(), nullable=True), sa.Column('away_goals', sa.Integer(), nullable=True), sa.Column('home_ht_goals', sa.Integer(), nullable=True), sa.Column('away_ht_goals', sa.Integer(), nullable=True), sa.Column('match_stage', sa.String(length=100), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), nullable=True), sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True), sa.ForeignKeyConstraint(['away_team_id'], ['teams.id'], ), sa.ForeignKeyConstraint(['home_team_id'], ['teams.id'], ), sa.ForeignKeyConstraint(['league_id'], ['leagues.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index('ix_matches_away_date', 'matches', ['away_team_id', sa.text('match_date DESC')], unique=False) op.create_index('ix_matches_home_date', 'matches', ['home_team_id', sa.text('match_date DESC')], unique=False) op.create_index('ix_matches_league_date', 'matches', ['league_id', sa.text('match_date DESC')], unique=False) op.create_index('ix_matches_status_date', 'matches', ['match_status', sa.text('match_date DESC')], unique=False) op.create_index('ix_matches_unique', 'matches', ['league_id', 'home_team_id', 'away_team_id', 'match_date_date'], unique=True) op.create_index(op.f('ix_matches_match_date_date'), 'matches', ['match_date_date'], unique=False) op.create_table('match_stats', sa.Column('match_id', sa.Integer(), nullable=False), sa.Column('home_xg', sa.Float(), nullable=True), sa.Column('away_xg', sa.Float(), nullable=True), sa.Column('home_shots', sa.Integer(), nullable=True), sa.Column('away_shots', sa.Integer(), nullable=True), sa.Column('home_shots_on_target', sa.Integer(), nullable=True), sa.Column('away_shots_on_target', sa.Integer(), nullable=True), sa.Column('home_corners', sa.Integer(), nullable=True), sa.Column('away_corners', sa.Integer(), nullable=True), sa.Column('home_possession', sa.Float(), nullable=True), sa.Column('home_yellow_cards', sa.Integer(), nullable=True), sa.Column('away_yellow_cards', sa.Integer(), nullable=True), sa.Column('home_red_cards', sa.Integer(), nullable=True), sa.Column('away_red_cards', sa.Integer(), nullable=True), sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True), sa.ForeignKeyConstraint(['match_id'], ['matches.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('match_id') ) op.create_table('predictions', sa.Column('id', sa.Integer(), nullable=False), sa.Column('match_id', sa.Integer(), nullable=False), sa.Column('provider', sa.String(length=30), nullable=False), sa.Column('model', sa.String(length=80), nullable=False), sa.Column('prompt_version', sa.String(length=20), nullable=False), sa.Column('prompt_tokens', sa.Integer(), nullable=True), sa.Column('completion_tokens', sa.Integer(), nullable=True), sa.Column('latency_ms', sa.Integer(), nullable=True), sa.Column('pred_home_goals', sa.Float(), nullable=True), sa.Column('pred_away_goals', sa.Float(), nullable=True), sa.Column('pred_1x2', sa.String(length=3), nullable=True), sa.Column('confidence', sa.Float(), nullable=True), sa.Column('reasoning', sa.Text(), nullable=True), sa.Column('raw_response', postgresql.JSONB(astext_type=sa.Text()), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), nullable=True), sa.Column('actual_home_goals', sa.Integer(), nullable=True), sa.Column('actual_away_goals', sa.Integer(), nullable=True), sa.Column('settled', sa.Boolean(), nullable=False), sa.ForeignKeyConstraint(['match_id'], ['matches.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_predictions_match'), 'predictions', ['match_id'], unique=False) op.create_index('ix_predictions_provider_model', 'predictions', ['provider', 'model'], unique=False) # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic ### op.drop_index('ix_predictions_provider_model', table_name='predictions') op.drop_index(op.f('ix_predictions_match'), table_name='predictions') op.drop_table('predictions') op.drop_table('match_stats') op.drop_index(op.f('ix_matches_match_date_date'), table_name='matches') op.drop_index('ix_matches_unique', table_name='matches') op.drop_index('ix_matches_status_date', table_name='matches') op.drop_index('ix_matches_league_date', table_name='matches') op.drop_index('ix_matches_home_date', table_name='matches') op.drop_index('ix_matches_away_date', table_name='matches') op.drop_table('matches') op.drop_table('teams') op.drop_table('leagues') # ### end Alembic commands ###