"""final version

Revision ID: ea13d116cff2
Revises: 
Create Date: 2019-01-04 15:31:57.412642

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'ea13d116cff2'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('federation',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('initials', sa.String(length=8), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_federation_initials'), 'federation', ['initials'], unique=False)
    op.create_index(op.f('ix_federation_name'), 'federation', ['name'], unique=True)
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('email', sa.String(length=120), nullable=True),
    sa.Column('password_hash', sa.String(length=128), nullable=True),
    sa.Column('birth', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_user_birth'), 'user', ['birth'], unique=False)
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
    op.create_index(op.f('ix_user_name'), 'user', ['name'], unique=True)
    op.create_table('ranking',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('federation', sa.Integer(), nullable=True),
    sa.Column('player_id', sa.String(), nullable=True),
    sa.Column('elo', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['federation'], ['federation.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_ranking_federation'), 'ranking', ['federation'], unique=False)
    op.create_index(op.f('ix_ranking_player_id'), 'ranking', ['player_id'], unique=False)
    op.create_index(op.f('ix_ranking_user_id'), 'ranking', ['user_id'], unique=False)
    op.create_table('tournament',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=128), nullable=True),
    sa.Column('place', sa.String(length=64), nullable=True),
    sa.Column('federation', sa.Integer(), nullable=True),
    sa.Column('start_date', sa.String(), nullable=True),
    sa.Column('end_date', sa.String(), nullable=True),
    sa.Column('rounds', sa.Integer(), nullable=True),
    sa.Column('play_system', sa.String(length=64), nullable=True),
    sa.Column('move_rate', sa.String(length=128), nullable=True),
    sa.Column('chief_arbiter', sa.String(length=128), nullable=True),
    sa.Column('deputy_arbiter', sa.String(length=256), nullable=True),
    sa.Column('organizer', sa.Integer(), nullable=True),
    sa.Column('categories', sa.String(length=128), nullable=True),
    sa.Column('information', sa.String(length=1024), nullable=True),
    sa.ForeignKeyConstraint(['federation'], ['federation.id'], ),
    sa.ForeignKeyConstraint(['organizer'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_tournament_name'), 'tournament', ['name'], unique=False)
    op.create_table('registration',
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('tournament_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.String(length=64), nullable=True),
    sa.ForeignKeyConstraint(['tournament_id'], ['tournament.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('user_id', 'tournament_id')
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('registration')
    op.drop_index(op.f('ix_tournament_name'), table_name='tournament')
    op.drop_table('tournament')
    op.drop_index(op.f('ix_ranking_user_id'), table_name='ranking')
    op.drop_index(op.f('ix_ranking_player_id'), table_name='ranking')
    op.drop_index(op.f('ix_ranking_federation'), table_name='ranking')
    op.drop_table('ranking')
    op.drop_index(op.f('ix_user_name'), table_name='user')
    op.drop_index(op.f('ix_user_email'), table_name='user')
    op.drop_index(op.f('ix_user_birth'), table_name='user')
    op.drop_table('user')
    op.drop_index(op.f('ix_federation_name'), table_name='federation')
    op.drop_index(op.f('ix_federation_initials'), table_name='federation')
    op.drop_table('federation')
    # ### end Alembic commands ###
