"""ADD github org url

Revision ID: 2af8f3918f87
Revises: 31dc6a1a6759
Create Date: 2021-05-23 10:42:43.278835

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

# revision identifiers, used by Alembic.
revision = "2af8f3918f87"
down_revision = "31dc6a1a6759"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("course", sa.Column("github_org_url", sa.TEXT(), nullable=True))
    op.alter_column(
        "static_file",
        "course_id",
        existing_type=mysql.VARCHAR(length=128),
        nullable=False,
    )
    op.alter_column(
        "theia_session",
        "course_id",
        existing_type=mysql.VARCHAR(length=128),
        nullable=False,
    )
    conn = op.get_bind()
    with conn.begin():
        conn.execute("update course set github_org_url = 'https://github.com/os3224';")
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "theia_session",
        "course_id",
        existing_type=mysql.VARCHAR(length=128),
        nullable=True,
    )
    op.alter_column(
        "static_file",
        "course_id",
        existing_type=mysql.VARCHAR(length=128),
        nullable=True,
    )
    op.drop_column("course", "github_org_url")
    # ### end Alembic commands ###
