"""athlete stage result ralation second try commit

Revision ID: 0c0b50dbb87d
Revises: 5afe7620ecb4
Create Date: 2021-09-29 14:31:40.249121

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

# revision identifiers, used by Alembic.
revision = '0c0b50dbb87d'
down_revision = '5afe7620ecb4'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('stage_athlete',
    sa.Column('stage_id', sa.Integer(), nullable=True),
    sa.Column('athlete_id', sa.Integer(), nullable=True),
    sa.Column('result_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['athlete_id'], ['athletes.id'], ),
    sa.ForeignKeyConstraint(['result_id'], ['results.id'], ),
    sa.ForeignKeyConstraint(['stage_id'], ['stages.id'], )
    )
    op.drop_constraint('results_ibfk_1', 'results', type_='foreignkey')
    op.drop_constraint('results_ibfk_2', 'results', type_='foreignkey')
    op.drop_column('results', 'stage_id')
    op.drop_column('results', 'athlete_id')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('results', sa.Column('athlete_id', mysql.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('results', sa.Column('stage_id', mysql.INTEGER(), autoincrement=False, nullable=True))
    op.create_foreign_key('results_ibfk_2', 'results', 'stages', ['stage_id'], ['id'])
    op.create_foreign_key('results_ibfk_1', 'results', 'athletes', ['athlete_id'], ['id'])
    op.drop_table('stage_athlete')
    # ### end Alembic commands ###
