"""Unique constraint on admin references

Revision ID: f9ba798f4042
Revises: 07007a76f428
Create Date: 2020-04-24 15:27:36.782568

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "f9ba798f4042"
down_revision = "07007a76f428"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_index(
        "ix_unique_admin_reference",
        "reference",
        ["poll_id", "user_id", "message_id"],
        unique=True,
        postgresql_where=sa.text("type = 'admin'"),
    )
    op.alter_column(
        "user_statistic",
        "votes",
        existing_type=sa.INTEGER(),
        server_default=None,
        existing_nullable=False,
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "user_statistic",
        "votes",
        existing_type=sa.INTEGER(),
        server_default=sa.text("0"),
        existing_nullable=False,
    )
    op.drop_index("ix_unique_admin_reference", table_name="reference")
    # ### end Alembic commands ###
