"""empty message

Revision ID: 6a343ff9bc2f
Revises: 
Create Date: 2020-09-11 17:22:38.129031

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "6a343ff9bc2f"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "experiments",
        sa.Column(
            "experiment_id",
            sa.BigInteger().with_variant(sa.Integer(), "sqlite"),
            nullable=False,
        ),
        sa.Column("created_on", sa.DateTime(), nullable=True),
        sa.Column("last_modified", sa.DateTime(), nullable=True),
        sa.Column("name", sa.Text(), nullable=False),
        sa.PrimaryKeyConstraint("experiment_id"),
    )
    with op.batch_alter_table("experiments", schema=None) as batch_op:
        batch_op.create_index(batch_op.f("ix_experiments_name"), ["name"], unique=True)

    op.create_table(
        "jobs",
        sa.Column("job_id", sa.String(length=36), nullable=False),
        sa.Column("mlflow_run_id", sa.String(length=36), nullable=True),
        sa.Column("experiment_id", sa.BigInteger(), nullable=True),
        sa.Column("created_on", sa.DateTime(), nullable=True),
        sa.Column("last_modified", sa.DateTime(), nullable=True),
        sa.Column(
            "queue",
            sa.Enum("tensorflow_cpu", "tensorflow_gpu", name="jobqueue"),
            nullable=True,
        ),
        sa.Column("timeout", sa.Text(), nullable=True),
        sa.Column("workflow_uri", sa.Text(), nullable=True),
        sa.Column("entry_point", sa.Text(), nullable=True),
        sa.Column("entry_point_kwargs", sa.Text(), nullable=True),
        sa.Column("depends_on", sa.String(length=36), nullable=True),
        sa.Column(
            "status",
            sa.Enum(
                "queued", "started", "deferred", "finished", "failed", name="jobstatus"
            ),
            nullable=True,
        ),
        sa.ForeignKeyConstraint(
            ["experiment_id"],
            ["experiments.experiment_id"],
        ),
        sa.PrimaryKeyConstraint("job_id"),
    )
    with op.batch_alter_table("jobs", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_jobs_experiment_id"), ["experiment_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_jobs_mlflow_run_id"), ["mlflow_run_id"], unique=False
        )
        batch_op.create_index(batch_op.f("ix_jobs_queue"), ["queue"], unique=False)

    # ### end Alembic commands ###


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

    op.drop_table("jobs")
    with op.batch_alter_table("experiments", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_experiments_name"))

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