"""FIX index issues

Revision ID: 2324a3537ff3
Revises: 51a4f35fc53e
Create Date: 2021-05-04 18:07:25.202120

"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "2324a3537ff3"
down_revision = "51a4f35fc53e"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    try:
        op.create_unique_constraint(None, "assignment", ["pipeline_image"])
    except:
        print("assignment pipeline unique constraint already exists")

    try:
        op.create_unique_constraint(None, "assignment", ["name"])
    except:
        print("assignment name unique constraint already exists")

    try:
        op.create_index(
            op.f("ix_assignment_test_name"),
            "assignment_test",
            ["name"],
            unique=False,
        )
    except:
        print("assignment assignment test name index already exists")

    try:
        op.create_index(
            op.f("ix_user_github_username"),
            "user",
            ["github_username"],
            unique=False,
        )
    except:
        print("user github username index already exists")
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_user_github_username"), table_name="user")
    op.drop_index(op.f("ix_assignment_test_name"), table_name="assignment_test")
    op.drop_constraint("pipeline_image", "assignment", type_="unique")
    op.drop_constraint("name", "assignment", type_="unique")
    # ### end Alembic commands ###
