"""v3.10: Add case-insensitive usernames in policies

Revision ID: db6b2ef8100f
Revises: d0e7144947d0
Create Date: 2024-01-29 14:12:38.070014

"""

# revision identifiers, used by Alembic.
revision = 'db6b2ef8100f'
down_revision = 'd0e7144947d0'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.exc import OperationalError, ProgrammingError

def upgrade():
    try:
        # ### commands auto generated by Alembic - please adjust! ###
        op.add_column('policy', sa.Column('user_case_insensitive', sa.Boolean(), nullable=True))
        # ### end Alembic commands ###
    except (OperationalError, ProgrammingError) as exx:
        if any(x in str(exx.orig).lower() for x in ["already exists", "duplicate column name"]):
            print("Ok, column 'user_case_insensitive' already exists.")
        else:
            print(exx)
            raise
    except Exception as exx:
        print(f"Could not add column 'user_case_insensitive' to database: {exx}")
        raise


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('policy', 'user_case_insensitive')
    # ### end Alembic commands ###
