"""empty message

Revision ID: 6634c8f0b7fc
Revises: becc71f97606
Create Date: 2023-05-31 22:37:22.719433

"""
import sqlalchemy as sa
import sqlalchemy_utils
from alembic import op

from project import dbtypes
from project.models import (
    AdminUnitVerificationRequestRejectionReason,
    AdminUnitVerificationRequestReviewStatus,
)

# revision identifiers, used by Alembic.
revision = "6634c8f0b7fc"
down_revision = "becc71f97606"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "adminunitverificationrequest",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("source_admin_unit_id", sa.Integer(), nullable=False),
        sa.Column("target_admin_unit_id", sa.Integer(), nullable=False),
        sa.Column(
            "review_status",
            dbtypes.IntegerEnum(AdminUnitVerificationRequestReviewStatus),
            nullable=True,
        ),
        sa.Column(
            "rejection_reason",
            dbtypes.IntegerEnum(AdminUnitVerificationRequestRejectionReason),
            nullable=True,
        ),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("created_by_id", sa.Integer(), nullable=True),
        sa.Column("updated_by_id", sa.Integer(), nullable=True),
        sa.CheckConstraint(
            "source_admin_unit_id != target_admin_unit_id",
            name=op.f("ck_adminunitverificationrequest_auvr_source_neq_target"),
        ),
        sa.ForeignKeyConstraint(
            ["created_by_id"],
            ["user.id"],
            name=op.f("fk_adminunitverificationrequest_created_by_id_user"),
            ondelete="SET NULL",
        ),
        sa.ForeignKeyConstraint(
            ["source_admin_unit_id"],
            ["adminunit.id"],
            name=op.f("fk_adminunitverificationrequest_source_admin_unit_id_adminunit"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["target_admin_unit_id"],
            ["adminunit.id"],
            name=op.f("fk_adminunitverificationrequest_target_admin_unit_id_adminunit"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["updated_by_id"],
            ["user.id"],
            name=op.f("fk_adminunitverificationrequest_updated_by_id_user"),
            ondelete="SET NULL",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_adminunitverificationrequest")),
        sa.UniqueConstraint(
            "source_admin_unit_id",
            "target_admin_unit_id",
            name=op.f("uq_adminunitverificationrequest_source_admin_unit_id"),
        ),
    )
    op.add_column(
        "adminunit", sa.Column("description", sa.UnicodeText(), nullable=True)
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("adminunit", "description")
    op.drop_table("adminunitverificationrequest")
    # ### end Alembic commands ###
