"""ADD theia_image 

Revision ID: a143a9fa5199
Revises: 11d4896fa6d1
Create Date: 2021-12-19 15:54:54.108047

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "a143a9fa5199"
down_revision = "11d4896fa6d1"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "theia_image_tag",
        sa.Column("id", sa.String(length=128), nullable=False),
        sa.Column("image_id", sa.String(length=128), nullable=False),
        sa.Column("tag", sa.String(length=256), nullable=False),
        sa.Column("title", sa.String(length=1024), nullable=False),
        sa.Column("description", sa.String(length=1024), nullable=False),
        sa.ForeignKeyConstraint(
            ["image_id"],
            ["theia_image.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        mysql_charset="utf8mb4",
        mysql_collate="utf8mb4_general_ci",
    )
    op.add_column(
        "assignment",
        sa.Column("theia_image_tag_id", sa.String(length=128), nullable=True),
    )
    op.create_foreign_key(None, "assignment", "theia_image_tag", ["theia_image_tag_id"], ["id"])
    op.add_column(
        "theia_image",
        sa.Column("default_tag", sa.String(length=128), nullable=True),
    )
    op.add_column(
        "theia_session",
        sa.Column("image_tag_id", sa.String(length=128), nullable=True),
    )
    op.create_foreign_key(None, "theia_session", "theia_image_tag", ["image_tag_id"], ["id"])
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, "theia_session", type_="foreignkey")
    op.drop_column("theia_session", "image_tag_id")
    op.drop_column("theia_image", "default_tag")
    op.drop_constraint(None, "assignment", type_="foreignkey")
    op.drop_column("assignment", "theia_image_tag_id")
    op.drop_table("theia_image_tag")
    # ### end Alembic commands ###
