"""empty message

Revision ID: 58d8aae621e6
Revises: cbac4166f9c0
Create Date: 2023-04-28 11:26:33.237832

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

from project import dbtypes

# revision identifiers, used by Alembic.
revision = "58d8aae621e6"
down_revision = "cbac4166f9c0"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_unique_constraint(
        op.f("uq_eventlist_name"), "eventlist", ["name", "admin_unit_id"]
    )
    op.add_column(
        "oauth2_token",
        sa.Column(
            "access_token_revoked_at", sa.Integer(), nullable=False, server_default="0"
        ),
    )
    op.add_column(
        "oauth2_token",
        sa.Column(
            "refresh_token_revoked_at", sa.Integer(), nullable=False, server_default="0"
        ),
    )
    op.drop_column("oauth2_token", "revoked")
    op.alter_column(
        "user",
        "newsletter_enabled",
        existing_type=sa.BOOLEAN(),
        nullable=True,
        existing_server_default=sa.text("true"),
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "user",
        "newsletter_enabled",
        existing_type=sa.BOOLEAN(),
        nullable=False,
        existing_server_default=sa.text("true"),
    )
    op.add_column(
        "oauth2_token",
        sa.Column("revoked", sa.BOOLEAN(), autoincrement=False, nullable=True),
    )
    op.drop_column("oauth2_token", "refresh_token_revoked_at")
    op.drop_column("oauth2_token", "access_token_revoked_at")
    op.drop_constraint(op.f("uq_eventlist_name"), "eventlist", type_="unique")
    # ### end Alembic commands ###
