"""ADD reserved ide time

Revision ID: 9ced7348c1b7
Revises: fd22cdd54047
Create Date: 2023-01-18 16:08:21.276639

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

# revision identifiers, used by Alembic.
revision = "9ced7348c1b7"
down_revision = "fd22cdd54047"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "reserved_ide_time",
        sa.Column(
            "id",
            mysql.VARCHAR(
                charset="utf8mb4", collation="utf8mb4_general_ci", length=36
            ),
            nullable=False,
        ),
        sa.Column(
            "course_id",
            mysql.VARCHAR(
                charset="utf8mb4", collation="utf8mb4_general_ci", length=36
            ),
            nullable=True,
        ),
        sa.Column(
            "assignment_id",
            mysql.VARCHAR(
                charset="utf8mb4", collation="utf8mb4_general_ci", length=36
            ),
            nullable=True,
        ),
        sa.Column("start", sa.DateTime(), nullable=True),
        sa.Column("end", sa.DateTime(), nullable=True),
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.Column("last_updated", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["assignment_id"],
            ["assignment.id"],
        ),
        sa.ForeignKeyConstraint(
            ["course_id"],
            ["course.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        mysql_charset="utf8mb4",
        mysql_collate="utf8mb4_general_ci",
    )
    with op.batch_alter_table("reserved_ide_time", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_reserved_ide_time_id"), ["id"], unique=False
        )


    # ### end Alembic commands ###


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

    op.drop_table("reserved_ide_time")
    # ### end Alembic commands ###
