<gh_stars>1-10
"""Add tables for tournaments feature

Revision ID: d172bd5e57c1
Revises: <PASSWORD>
Create Date: 2018-12-31 11:54:48.926336

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd172bd5e57c1'
down_revision = '<PASSWORD>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tournament_bots',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('elo', sa.Float(), nullable=True),
    sa.Column('wins', sa.Integer(), nullable=True),
    sa.Column('losses', sa.Integer(), nullable=True),
    sa.Column('bot_id', sa.Integer(), nullable=False),
    sa.Column('tournament_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['bot_id'], ['bots.id'], ),
    sa.ForeignKeyConstraint(['tournament_id'], ['tournaments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('tournament_games',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('tournament_id', sa.Integer(), nullable=False),
    sa.Column('bot_a_id', sa.Integer(), nullable=False),
    sa.Column('bot_a_elo', sa.Float(), nullable=True),
    sa.Column('bot_b_id', sa.Integer(), nullable=False),
    sa.Column('bot_b_elo', sa.Float(), nullable=True),
    sa.Column('winner_id', sa.Integer(), nullable=True),
    sa.Column('loser_id', sa.Integer(), nullable=True),
    sa.Column('status', sa.Enum('completed', 'created', 'in_progress', 'internal_error', name='gamestatus'), nullable=False),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.Column('completed_time', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['bot_a_id'], ['tournament_bots.id'], ),
    sa.ForeignKeyConstraint(['bot_b_id'], ['tournament_bots.id'], ),
    sa.ForeignKeyConstraint(['loser_id'], ['tournament_bots.id'], ),
    sa.ForeignKeyConstraint(['tournament_id'], ['tournaments.id'], ),
    sa.ForeignKeyConstraint(['winner_id'], ['tournament_bots.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('tournaments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=256), nullable=True),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.Column('games_per_pair', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('tournaments')
    op.drop_table('tournament_games')
    op.drop_table('tournament_bots')
    # ### end Alembic commands ###
