"""CHG assignment test output types

Revision ID: 7bce3314f2d8
Revises: 28971042fc9c
Create Date: 2022-01-15 19:53:48.734288

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

# revision identifiers, used by Alembic.
revision = "7bce3314f2d8"
down_revision = "28971042fc9c"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "submission_test_result",
        sa.Column("output_type", sa.String(length=128), nullable=True),
    )
    op.add_column(
        "submission_test_result",
        sa.Column("output", sa.Text(length=65536), nullable=True),
    )
    conn = op.get_bind()
    with conn.begin():
        conn.execute('update submission_test_result set `output` = `stdout`;')
        conn.execute('update submission_test_result set `output_type` = \'text\';')
    op.drop_column("submission_test_result", "stdout")
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "submission_test_result",
        sa.Column("stdout", mysql.TEXT(), nullable=True),
    )
    op.drop_column("submission_test_result", "output")
    op.drop_column("submission_test_result", "output_type")
    # ### end Alembic commands ###
