"""update a lot of Python libraries

Revision ID: c5428295e344
Revises: 3b969fcf37be
Create Date: 2025-09-21 09:09:56.896474+00:00

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'c5428295e344'
down_revision = '3b969fcf37be'
branch_labels = None
depends_on = None


def upgrade():
    usertag = sa.Enum('Quality', 'Good', 'Comment', 'Warning', 'Tempban', 'Permban', 'Spam', 'Bot', name='usertag')
    usertag.create(op.get_bind(), checkfirst=True)

	# ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('client_auths', schema=None) as batch_op:
        batch_op.alter_column('access_token',
               existing_type=sa.CHAR(length=128),
               type_=sa.String(length=128),
               existing_nullable=False)

    with op.batch_alter_table('oauth_apps', schema=None) as batch_op:
        batch_op.alter_column('client_id',
               existing_type=sa.CHAR(length=64),
               type_=sa.String(length=64),
               existing_nullable=True)
        batch_op.alter_column('redirect_uri',
               existing_type=sa.VARCHAR(length=4096),
               type_=sa.String(length=50),
               existing_nullable=False)

    # Can't use batch_alter_table for enum conversion with USING clause
    op.execute("ALTER TABLE usernotes ALTER COLUMN tag TYPE usertag USING tag::usertag")

    # ### end Alembic commands ###


def downgrade():
	# ### commands auto generated by Alembic - please adjust! ###
    # Convert enum back to varchar
    op.execute("ALTER TABLE usernotes ALTER COLUMN tag TYPE VARCHAR(10) USING tag::text")

    with op.batch_alter_table('oauth_apps', schema=None) as batch_op:
        batch_op.alter_column('redirect_uri',
               existing_type=sa.String(length=50),
               type_=sa.VARCHAR(length=4096),
               existing_nullable=False)
        batch_op.alter_column('client_id',
               existing_type=sa.String(length=64),
               type_=sa.CHAR(length=64),
               existing_nullable=True)

    with op.batch_alter_table('client_auths', schema=None) as batch_op:
        batch_op.alter_column('access_token',
               existing_type=sa.String(length=128),
               type_=sa.CHAR(length=128),
               existing_nullable=False)

    # Drop the enum type after converting back to varchar
    usertag = sa.Enum('Quality', 'Good', 'Comment', 'Warning', 'Tempban', 'Permban', 'Spam', 'Bot', name='usertag')
    usertag.drop(op.get_bind(), checkfirst=True)

    # ### end Alembic commands ###
