"""initial

Revision ID: 7883d80258fb
Revises:
Create Date: 2022-04-07 15:41:46.233567

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

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


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "configuration_variable",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("key", sa.String(), nullable=True),
        sa.Column("raw_value", sa.String(length=254), nullable=True),
        sa.Column(
            "variable_type",
            sa.Enum("BOOL", "INT", "STR", name="variabletype"),
            nullable=True,
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("key"),
    )
    op.create_table(
        "diff_warning",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("revision_id", sa.Integer(), nullable=False),
        sa.Column("diff_id", sa.Integer(), nullable=False),
        sa.Column("data", postgresql.JSONB(astext_type=sa.Text()), nullable=False),
        sa.Column(
            "status",
            sa.Enum("ACTIVE", "ARCHIVED", name="diffwarningstatus"),
            nullable=False,
        ),
        sa.Column(
            "group", sa.Enum("GENERAL", "LINT", name="diffwarninggroup"), nullable=False
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "landing_job",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column(
            "status",
            sa.Enum(
                "SUBMITTED",
                "IN_PROGRESS",
                "DEFERRED",
                "FAILED",
                "LANDED",
                "CANCELLED",
                name="landingjobstatus",
            ),
            nullable=False,
        ),
        sa.Column(
            "revision_to_diff_id",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=False,
        ),
        sa.Column(
            "revision_order", postgresql.JSONB(astext_type=sa.Text()), nullable=False
        ),
        sa.Column("error", sa.Text(), nullable=True),
        sa.Column(
            "error_breakdown", postgresql.JSONB(astext_type=sa.Text()), nullable=True
        ),
        sa.Column("requester_email", sa.String(length=254), nullable=False),
        sa.Column("repository_name", sa.Text(), nullable=False),
        sa.Column("repository_url", sa.Text(), nullable=True),
        sa.Column("landed_commit_id", sa.Text(), nullable=True),
        sa.Column("attempts", sa.Integer(), nullable=False),
        sa.Column("priority", sa.Integer(), nullable=False),
        sa.Column("duration_seconds", sa.Integer(), nullable=True),
        sa.Column(
            "formatted_replacements",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "secapproval_requests",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("revision_id", sa.Integer(), nullable=False),
        sa.Column("diff_phid", sa.Text(), nullable=False),
        sa.Column(
            "comment_candidates",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_secapproval_requests_revision_id"),
        "secapproval_requests",
        ["revision_id"],
        unique=False,
    )
    op.create_table(
        "transplants",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("request_id", sa.Integer(), nullable=True),
        sa.Column(
            "status",
            sa.Enum(
                "aborted", "submitted", "landed", "failed", name="transplantstatus"
            ),
            nullable=False,
        ),
        sa.Column(
            "revision_to_diff_id",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=False,
        ),
        sa.Column(
            "revision_order", postgresql.JSONB(astext_type=sa.Text()), nullable=False
        ),
        sa.Column("error", sa.Text(), nullable=True),
        sa.Column("result", sa.Text(), nullable=True),
        sa.Column("requester_email", sa.String(length=254), nullable=True),
        sa.Column("repository_url", sa.Text(), nullable=True),
        sa.Column("tree", sa.String(length=128), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("request_id"),
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("transplants")
    op.drop_index(
        op.f("ix_secapproval_requests_revision_id"), table_name="secapproval_requests"
    )
    op.drop_table("secapproval_requests")
    op.drop_table("landing_job")
    op.drop_table("diff_warning")
    op.drop_table("configuration_variable")
    # ### end Alembic commands ###
