"""Initial database

Revision ID: 8e77bf12d068
Revises: 
Create Date: 2018-12-27 13:15:47.460236

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('bots',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('team_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=False),
    sa.Column('s3_key', sa.String(length=256), nullable=False),
    sa.Column('wins', sa.Integer(), nullable=True),
    sa.Column('losses', sa.Integer(), nullable=True),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('game_requests',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('challenger_id', sa.Integer(), nullable=False),
    sa.Column('opponent_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.Enum('accepted', 'challenged', 'rejected', name='gamerequeststatus'), nullable=False),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['challenger_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['opponent_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('games',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('game_request_id', sa.Integer(), nullable=False),
    sa.Column('initiator_id', sa.Integer(), nullable=False),
    sa.Column('challenger_id', sa.Integer(), nullable=False),
    sa.Column('opponent_id', sa.Integer(), nullable=False),
    sa.Column('challenger_elo', sa.Float(), nullable=True),
    sa.Column('opponent_elo', sa.Float(), nullable=True),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.Column('completed_time', sa.DateTime(), nullable=True),
    sa.Column('status', sa.Enum('completed', 'created', 'in_progress', 'internal_error', name='gamestatus'), nullable=False),
    sa.Column('challenger_bot_id', sa.Integer(), nullable=False),
    sa.Column('opponent_bot_id', sa.Integer(), nullable=False),
    sa.Column('winner_id', sa.Integer(), nullable=True),
    sa.Column('loser_id', sa.Integer(), nullable=True),
    sa.Column('log_s3_key', sa.String(length=256), nullable=True),
    sa.ForeignKeyConstraint(['challenger_bot_id'], ['bots.id'], ),
    sa.ForeignKeyConstraint(['challenger_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['game_request_id'], ['game_requests.id'], ),
    sa.ForeignKeyConstraint(['initiator_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['loser_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['opponent_bot_id'], ['bots.id'], ),
    sa.ForeignKeyConstraint(['opponent_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['winner_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('game_request_id')
    )
    op.create_table('settings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('key', sa.String(length=128), nullable=True),
    sa.Column('value', sa.String(length=128), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_settings_key'), 'settings', ['key'], unique=True)
    op.create_index(op.f('ix_settings_value'), 'settings', ['value'], unique=True)
    op.create_table('teams',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=True),
    sa.Column('elo', sa.Float(), nullable=True),
    sa.Column('wins', sa.Integer(), nullable=True),
    sa.Column('losses', sa.Integer(), nullable=True),
    sa.Column('current_bot_id', sa.Integer(), nullable=True),
    sa.Column('is_disabled', sa.Boolean(), nullable=True),
    sa.Column('must_autoaccept', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['current_bot_id'], ['bots.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('kerberos', sa.String(length=128), nullable=True),
    sa.Column('team_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_kerberos'), 'users', ['kerberos'], unique=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_users_kerberos'), table_name='users')
    op.drop_table('users')
    op.drop_table('teams')
    op.drop_index(op.f('ix_settings_value'), table_name='settings')
    op.drop_index(op.f('ix_settings_key'), table_name='settings')
    op.drop_table('settings')
    op.drop_table('games')
    op.drop_table('game_requests')
    op.drop_table('bots')
    # ### end Alembic commands ###

"""Initial database

Revision ID: 8e77bf12d068
Revises: 
Create Date: 2018-12-27 13:15:47.460236

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('bots',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('team_id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=False),
    sa.Column('s3_key', sa.String(length=256), nullable=False),
    sa.Column('wins', sa.Integer(), nullable=True),
    sa.Column('losses', sa.Integer(), nullable=True),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('game_requests',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('challenger_id', sa.Integer(), nullable=False),
    sa.Column('opponent_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.Enum('accepted', 'challenged', 'rejected', name='gamerequeststatus'), nullable=False),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['challenger_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['opponent_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('games',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('game_request_id', sa.Integer(), nullable=False),
    sa.Column('initiator_id', sa.Integer(), nullable=False),
    sa.Column('challenger_id', sa.Integer(), nullable=False),
    sa.Column('opponent_id', sa.Integer(), nullable=False),
    sa.Column('challenger_elo', sa.Float(), nullable=True),
    sa.Column('opponent_elo', sa.Float(), nullable=True),
    sa.Column('create_time', sa.DateTime(), nullable=True),
    sa.Column('completed_time', sa.DateTime(), nullable=True),
    sa.Column('status', sa.Enum('completed', 'created', 'in_progress', 'internal_error', name='gamestatus'), nullable=False),
    sa.Column('challenger_bot_id', sa.Integer(), nullable=False),
    sa.Column('opponent_bot_id', sa.Integer(), nullable=False),
    sa.Column('winner_id', sa.Integer(), nullable=True),
    sa.Column('loser_id', sa.Integer(), nullable=True),
    sa.Column('log_s3_key', sa.String(length=256), nullable=True),
    sa.ForeignKeyConstraint(['challenger_bot_id'], ['bots.id'], ),
    sa.ForeignKeyConstraint(['challenger_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['game_request_id'], ['game_requests.id'], ),
    sa.ForeignKeyConstraint(['initiator_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['loser_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['opponent_bot_id'], ['bots.id'], ),
    sa.ForeignKeyConstraint(['opponent_id'], ['teams.id'], ),
    sa.ForeignKeyConstraint(['winner_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('game_request_id')
    )
    op.create_table('settings',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('key', sa.String(length=128), nullable=True),
    sa.Column('value', sa.String(length=128), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_settings_key'), 'settings', ['key'], unique=True)
    op.create_index(op.f('ix_settings_value'), 'settings', ['value'], unique=True)
    op.create_table('teams',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=True),
    sa.Column('elo', sa.Float(), nullable=True),
    sa.Column('wins', sa.Integer(), nullable=True),
    sa.Column('losses', sa.Integer(), nullable=True),
    sa.Column('current_bot_id', sa.Integer(), nullable=True),
    sa.Column('is_disabled', sa.Boolean(), nullable=True),
    sa.Column('must_autoaccept', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['current_bot_id'], ['bots.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('kerberos', sa.String(length=128), nullable=True),
    sa.Column('team_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_kerberos'), 'users', ['kerberos'], unique=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_users_kerberos'), table_name='users')
    op.drop_table('users')
    op.drop_table('teams')
    op.drop_index(op.f('ix_settings_value'), table_name='settings')
    op.drop_index(op.f('ix_settings_key'), table_name='settings')
    op.drop_table('settings')
    op.drop_table('games')
    op.drop_table('game_requests')
    op.drop_table('bots')
    # ### end Alembic commands ###

Initial database  Revision ID: 8e77bf12d068 Revises:  Create Date: 2018-12-27 13:15:47.460236 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###