# pylint: disable=invalid-name
"""AuditType.BALLOT_COMPARISON

Revision ID: 3edc260ab0b1
Revises: aa3978570981
Create Date: 2020-09-28 22:11:46.110113+00:00

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "3edc260ab0b1"
down_revision = "aa3978570981"
branch_labels = None
depends_on = None


def upgrade():
    # Alembic doesn't support changing enums, so we have to swap out the
    # existing enum with a new enum.
    # https://markrailton.com/blog/creating-migrations-when-changing-an-enum-in-python-using-sql-alchemy

    op.execute("ALTER TYPE audittype RENAME TO audittype_old")

    new_audit_type_enum = sa.dialects.postgresql.ENUM(
        "BALLOT_POLLING", "BATCH_COMPARISON", "BALLOT_COMPARISON", name="audittype"
    )
    new_audit_type_enum.create(op.get_bind())

    op.execute(
        "ALTER TABLE election ALTER COLUMN audit_type TYPE audittype USING audit_type::text::audittype"
    )

    op.execute("DROP TYPE audittype_old")


def downgrade():  # pragma: no cover
    # ### commands auto generated by Alembic - please adjust! ###
    pass
    # ### end Alembic commands ###
