"""Update QuizGameQuestions and QuizGameQuestionAnswers Relation

Revision ID: ce725aa41326
Revises: dcb1a0d764ee
Create Date: 2021-06-27 18:51:58.211732

"""
from alembic import op
import sqlalchemy as sa


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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('quiz_game_questions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('quizquestion_text', sa.String(), nullable=False),
    sa.Column('quizquestion_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['quizquestion_id'], ['quiz_questions.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('quiz_game_question_answers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('quizanswer_text', sa.String(), nullable=False),
    sa.Column('quizanswer_is_correct', sa.Boolean(), nullable=True),
    sa.Column('quizanswer_id', sa.Integer(), nullable=False),
    sa.Column('quizgame_question_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['quizanswer_id'], ['quiz_answers.id'], ),
    sa.ForeignKeyConstraint(['quizgame_question_id'], ['quiz_game_questions.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('quiz_game_question_question_answers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('quizgamequestion_id', sa.Integer(), nullable=True),
    sa.Column('quizgamequestionanswer_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['quizgamequestion_id'], ['quiz_game_questions.id'], ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['quizgamequestionanswer_id'], ['quiz_game_question_answers.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('quiz_games', sa.Column('quizgame_question_id', sa.Integer(), nullable=False))
    op.drop_constraint('quiz_games_quizgame_setup_id_fkey', 'quiz_games', type_='foreignkey')
    op.create_foreign_key(None, 'quiz_games', 'quiz_game_questions', ['quizgame_question_id'], ['id'])
    op.drop_column('quiz_games', 'quizgame_setup_id')

    op.drop_table('quiz_game_setup_answers')
    op.drop_table('quiz_game_setups')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('quiz_games', sa.Column('quizgame_setup_id', sa.INTEGER(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'quiz_games', type_='foreignkey')
    op.create_foreign_key('quiz_games_quizgame_setup_id_fkey', 'quiz_games', 'quiz_game_setups', ['quizgame_setup_id'], ['id'])
    op.drop_column('quiz_games', 'quizgame_question_id')
    op.create_table('quiz_game_setups',
    sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('quiz_game_setups_id_seq'::regclass)"), autoincrement=True, nullable=False),
    sa.Column('quizquestion_text', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('quizquestion_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['quizquestion_id'], ['quiz_questions.id'], name='quiz_game_setups_quizquestion_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='quiz_game_setups_pkey'),
    postgresql_ignore_search_path=False
    )
    op.create_table('quiz_game_setup_answers',
    sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('quizanswer_text', sa.VARCHAR(), autoincrement=False, nullable=False),
    sa.Column('quizanswer_is_correct', sa.BOOLEAN(), autoincrement=False, nullable=True),
    sa.Column('quizanswer_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('quizgamesetup_id', sa.INTEGER(), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['quizanswer_id'], ['quiz_answers.id'], name='quiz_game_setup_answers_quizanswer_id_fkey'),
    sa.ForeignKeyConstraint(['quizgamesetup_id'], ['quiz_game_setups.id'], name='quiz_game_setup_answers_quizgamesetup_id_fkey'),
    sa.PrimaryKeyConstraint('id', name='quiz_game_setup_answers_pkey')
    )
    op.drop_table('quiz_game_question_question_answers')
    op.drop_table('quiz_game_question_answers')
    op.drop_table('quiz_game_questions')
    # ### end Alembic commands ###
