"""ADD order to assignment tests

Revision ID: f24845d5da2e
Revises: 9344ba170f2c
Create Date: 2022-12-31 17:15:06.777701

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

# revision identifiers, used by Alembic.
revision = "f24845d5da2e"
down_revision = "9344ba170f2c"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("assignment_test", schema=None) as batch_op:
        batch_op.add_column(sa.Column("order", sa.Integer(), nullable=True))
        batch_op.create_index(
            batch_op.f("ix_assignment_test_order"), ["order"], unique=False
        )
    conn = op.get_bind()
    conn.execute('UPDATE `assignment_test` SET `order` = 0;')
    with op.batch_alter_table("assignment_test", schema=None) as batch_op:
        batch_op.alter_column("order", type_=sa.Integer(), nullable=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("assignment_test", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_assignment_test_order"))
        batch_op.drop_column("order")
    # ### end Alembic commands ###
