"""ADD TheiaPaste Model

Revision ID: 88db21968c0d
Revises: 8c17dcffa2be
Create Date: 2022-04-06 10:25:20.125746

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "88db21968c0d"
down_revision = "8c17dcffa2be"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "theia_paste",
        sa.Column("id", sa.String(length=128), nullable=False),
        sa.Column("user_id", sa.String(length=128), nullable=True),
        sa.Column("theia_session_id", sa.String(length=128), nullable=True),
        sa.Column("timestamp", sa.DateTime(), nullable=True),
        sa.Column("content", sa.LargeBinary(length=4096), nullable=True),
        sa.ForeignKeyConstraint(
            ["theia_session_id"],
            ["theia_session.id"],
        ),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["user.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        mysql_charset="utf8mb4",
        mysql_collate="utf8mb4_general_ci",
    )
    op.create_index(
        op.f("ix_theia_paste_theia_session_id"),
        "theia_paste",
        ["theia_session_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_theia_paste_user_id"),
        "theia_paste",
        ["user_id"],
        unique=False,
    )
    op.add_column(
        "assignment",
        sa.Column("anti_cheat_enabled", sa.Boolean(), nullable=True),
    )
    conn = op.get_bind()
    with conn.begin():
        conn.execute('update `assignment` set `anti_cheat_enabled` = 0;')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("assignment", "anti_cheat_enabled")
    op.drop_index(op.f("ix_theia_paste_user_id"), table_name="theia_paste")
    op.drop_index(
        op.f("ix_theia_paste_theia_session_id"), table_name="theia_paste"
    )
    op.drop_table("theia_paste")
    # ### end Alembic commands ###
