"""初赛题库

Revision ID: 9767248981d8
Revises: <PASSWORD>
Create Date: 2020-09-10 21:25:19.344089

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

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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('preliminary_contest',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', mysql.TEXT(), nullable=False),
    sa.Column('description', mysql.LONGTEXT(), nullable=True),
    sa.Column('uploader', sa.Integer(), nullable=False),
    sa.Column('duration', sa.Integer(), nullable=False),
    sa.Column('upload_time', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['uploader'], ['user.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_preliminary_contest_upload_time'), 'preliminary_contest', ['upload_time'], unique=False)
    op.create_index(op.f('ix_preliminary_contest_uploader'), 'preliminary_contest', ['uploader'], unique=False)
    op.create_table('preliminary_problem',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('contest', sa.Integer(), nullable=True),
    sa.Column('problem_type', sa.Enum('selection', 'fill_blank', name='preliminaryproblemtype'), nullable=True),
    sa.Column('problem_id', sa.Integer(), nullable=True),
    sa.Column('content', mysql.TEXT(), nullable=True),
    sa.Column('questions', ormtypes.json_pickle.JsonPickle(), nullable=True),
    sa.Column('score', sa.Float(), nullable=False),
    sa.ForeignKeyConstraint(['contest'], ['preliminary_contest.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_preliminary_problem_problem_id'), 'preliminary_problem', ['problem_id'], unique=False)
    op.create_index(op.f('ix_preliminary_problem_problem_type'), 'preliminary_problem', ['problem_type'], unique=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_preliminary_problem_problem_type'), table_name='preliminary_problem')
    op.drop_index(op.f('ix_preliminary_problem_problem_id'), table_name='preliminary_problem')
    op.drop_table('preliminary_problem')
    op.drop_index(op.f('ix_preliminary_contest_uploader'), table_name='preliminary_contest')
    op.drop_index(op.f('ix_preliminary_contest_upload_time'), table_name='preliminary_contest')
    op.drop_table('preliminary_contest')
    # ### end Alembic commands ###
