"""Increase password_hash column length

Revision ID: d8dcbf9fe881
Revises: 1c297825e3a9
Create Date: 2025-05-23 08:45:00.693155

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


# revision identifiers, used by Alembic.
revision = 'd8dcbf9fe881'
down_revision = '1c297825e3a9'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = inspect(conn)
    columns = [col['name'] for col in inspector.get_columns('user')]
    
    if 'password_hash' in columns:
        with op.batch_alter_table('user', schema=None) as batch_op:
            batch_op.alter_column('password_hash',
                   existing_type=sa.VARCHAR(length=128),
                   type_=sa.String(length=256),
                   existing_nullable=True)

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    conn = op.get_bind()
    inspector = inspect(conn)
    columns = [col['name'] for col in inspector.get_columns('user')]
    
    if 'password_hash' in columns:
        with op.batch_alter_table('user', schema=None) as batch_op:
            batch_op.alter_column('password_hash',
                   existing_type=sa.String(length=256),
                   type_=sa.VARCHAR(length=128),
                   existing_nullable=True)

    # ### end Alembic commands ###
