"""athlete stage result ralation initial commit

Revision ID: a166c166c35e
Revises: ffb1067151e6
Create Date: 2021-09-28 13:50:27.015640

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('results',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('athlete_id', sa.Integer(), nullable=True),
    sa.Column('stage_id', sa.Integer(), nullable=True),
    sa.Column('rank', sa.Integer(), nullable=True),
    sa.Column('time', sa.Time(), nullable=True),
    sa.ForeignKeyConstraint(['athlete_id'], ['athletes.id'], ),
    sa.ForeignKeyConstraint(['stage_id'], ['stages.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('stage_athlete',
    sa.Column('stage_id', sa.Integer(), nullable=True),
    sa.Column('athlete_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['athlete_id'], ['athletes.id'], ),
    sa.ForeignKeyConstraint(['stage_id'], ['stages.id'], )
    )
    op.drop_table('races')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('races',
    sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('athlete_id', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('stage_id', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('rank', mysql.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('time', mysql.TIME(), nullable=True),
    sa.ForeignKeyConstraint(['athlete_id'], ['athletes.id'], name='races_ibfk_1'),
    sa.ForeignKeyConstraint(['stage_id'], ['stages.id'], name='races_ibfk_2'),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    op.drop_table('stage_athlete')
    op.drop_table('results')
    # ### end Alembic commands ###
