"""Initial

Revision ID: a676aa29c936
Revises:
Create Date: 2020-10-13 13:53:46.436972

"""
import sqlalchemy as sa
from alembic import op

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


def upgrade():
    """
    commands auto generated by Alembic - please customize!
    """
    op.create_table(
        "annotators",
        sa.Column("id", sa.String(), nullable=False),
        sa.Column("name", sa.String(length=250), nullable=True),
        sa.Column("email", sa.String(length=250), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_annotators_id"), "annotators", ["id"], unique=False)
    op.create_table(
        "eventlog",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("payload", sa.JSON(), nullable=False),
        sa.Column("recorded", sa.DateTime(), nullable=False),
        sa.Column("stored", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_eventlog_id"), "eventlog", ["id"], unique=False)
    op.create_index(op.f("ix_eventlog_name"), "eventlog", ["name"], unique=False)
    op.create_table(
        "samples",
        sa.Column("id", sa.String(), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_samples_id"), "samples", ["id"], unique=False)
    op.create_table(
        "annotations",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("sample_id", sa.String(), nullable=False),
        sa.Column("annotator_id", sa.String(), nullable=True),
        sa.Column("labels", sa.ARRAY(sa.String()), nullable=True),
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["sample_id"],
            ["samples.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_annotations_annotator_id"),
        "annotations",
        ["annotator_id"],
        unique=False,
    )
    op.create_index(op.f("ix_annotations_id"), "annotations", ["id"], unique=False)
    op.create_index(
        op.f("ix_annotations_sample_id"), "annotations", ["sample_id"], unique=False
    )

    op.create_table(
        "skippedsamples",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("sample_id", sa.String(), nullable=False),
        sa.Column("annotator_id", sa.String(), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["sample_id"],
            ["samples.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_skippedsamples_annotator_id"),
        "skippedsamples",
        ["annotator_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_skippedsamples_id"), "skippedsamples", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_skippedsamples_sample_id"),
        "skippedsamples",
        ["sample_id"],
        unique=False,
    )

    op.create_table(
        "assignment",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("annotator_id", sa.String(), nullable=True),
        sa.Column("sample_id", sa.String(), nullable=True),
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["sample_id"],
            ["samples.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_assignment_annotator_id"), "assignment", ["annotator_id"], unique=False
    )
    op.create_index(op.f("ix_assignment_id"), "assignment", ["id"], unique=False)
    op.create_index(
        op.f("ix_assignment_sample_id"), "assignment", ["sample_id"], unique=False
    )
    op.create_table(
        "queriedsamples",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("sample_id", sa.String(), nullable=True),
        sa.Column("query_index", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["sample_id"],
            ["samples.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_sample_id"), "queriedsamples", ["sample_id"], unique=False)
    op.create_index(op.f("ix_queriedsample_id"), "queriedsamples", ["id"], unique=False)
    op.create_index(
        op.f("ix_query_index_id"), "queriedsamples", ["query_index"], unique=False
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_assignment_sample_id"), table_name="assignment")
    op.drop_index(op.f("ix_assignment_id"), table_name="assignment")
    op.drop_index(op.f("ix_assignment_annotator_id"), table_name="assignment")
    op.drop_table("assignment")
    op.drop_index(op.f("ix_annotations_sample_id"), table_name="annotations")
    op.drop_index(op.f("ix_annotations_id"), table_name="annotations")
    op.drop_index(op.f("ix_annotations_annotator_id"), table_name="annotations")
    op.drop_table("annotations")
    op.drop_index(op.f("ix_skippedsamples_sample_id"), table_name="skippedsamples")
    op.drop_index(op.f("ix_skippedsamples_id"), table_name="skippedsamples")
    op.drop_index(op.f("ix_skippedsamples_annotator_id"), table_name="skippedsamples")
    op.drop_table("skippedsamples")
    op.drop_index(op.f("ix_samples_id"), table_name="samples")
    op.drop_table("samples")
    op.drop_index(op.f("ix_eventlog_name"), table_name="eventlog")
    op.drop_index(op.f("ix_eventlog_id"), table_name="eventlog")
    op.drop_table("eventlog")
    op.drop_index(op.f("ix_annotators_id"), table_name="annotators")
    op.drop_table("annotators")
    op.drop_index(op.f("ix_sample_id"), table_name="queriedsamples")
    op.drop_index(op.f("ix_queriedsample_id"), table_name="queriedsamples")
    op.drop_index(op.f("ix_query_index_id"), table_name="queriedsamples")
    op.drop_table("queriedsamples")
    # ### end Alembic commands ###
