"""fix column types

Revision ID: 4157bb294b34
Revises: 9cbb06f7c97f
Create Date: 2025-03-04 10:04:04.790842

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '4157bb294b34'
down_revision: Union[str, None] = '9cbb06f7c97f'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    if op.get_bind().dialect.name == 'sqlite':
        # SQLite-specific operations
        with op.batch_alter_table('chatbots') as batch_op:
            batch_op.alter_column('name', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=True)
            batch_op.alter_column('botname', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=True)
            batch_op.alter_column('use_personality', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_mood', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_guardrails', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_system_instructions', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_datetime', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('assign_names', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_tool_filter', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_gpu', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('skip_special_tokens', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('random_seed', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('model_version', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=True)
            batch_op.alter_column('model_type', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=True)
            batch_op.alter_column('dtype', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=True)
            batch_op.alter_column('return_result', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('do_sample', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('early_stopping', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_cache', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_backstory', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
            batch_op.alter_column('use_weather_prompt', existing_type=sa.NUMERIC(), type_=sa.Boolean(), existing_nullable=True)
        
        with op.batch_alter_table('image_filter_values') as batch_op:
            batch_op.alter_column('name', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=False)
            batch_op.alter_column('value', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=False)
            batch_op.alter_column('value_type', existing_type=sa.TEXT(), type_=sa.String(), existing_nullable=False)
            batch_op.alter_column('min_value', existing_type=sa.REAL(), type_=sa.Float(), existing_nullable=True)
            batch_op.alter_column('max_value', existing_type=sa.REAL(), type_=sa.Float(), existing_nullable=True)
    else:
        # PostgreSQL and other databases
        op.alter_column('chatbots', 'name',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'botname',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_personality',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_mood',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_guardrails',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_system_instructions',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_datetime',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'assign_names',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_tool_filter',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_gpu',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'skip_special_tokens',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'random_seed',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'model_version',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'model_type',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'dtype',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'return_result',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'do_sample',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'early_stopping',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_cache',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_backstory',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_weather_prompt',
                   existing_type=sa.NUMERIC(),
                   type_=sa.Boolean(),
                   existing_nullable=True)
        op.alter_column('image_filter_values', 'name',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=False)
        op.alter_column('image_filter_values', 'value',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=False)
        op.alter_column('image_filter_values', 'value_type',
                   existing_type=sa.TEXT(),
                   type_=sa.String(),
                   existing_nullable=False)
        op.alter_column('image_filter_values', 'min_value',
                   existing_type=sa.REAL(),
                   type_=sa.Float(),
                   existing_nullable=True)
        op.alter_column('image_filter_values', 'max_value',
                   existing_type=sa.REAL(),
                   type_=sa.Float(),
                   existing_nullable=True)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    if op.get_bind().dialect.name == 'sqlite':
        # SQLite-specific operations
        with op.batch_alter_table('image_filter_values') as batch_op:
            batch_op.alter_column('max_value', existing_type=sa.Float(), type_=sa.REAL(), existing_nullable=True)
            batch_op.alter_column('min_value', existing_type=sa.Float(), type_=sa.REAL(), existing_nullable=True)
            batch_op.alter_column('value_type', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=False)
            batch_op.alter_column('value', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=False)
            batch_op.alter_column('name', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=False)
        
        with op.batch_alter_table('chatbots') as batch_op:
            batch_op.alter_column('use_weather_prompt', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_backstory', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_cache', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('early_stopping', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('do_sample', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('return_result', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('dtype', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=True)
            batch_op.alter_column('model_type', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=True)
            batch_op.alter_column('model_version', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=True)
            batch_op.alter_column('random_seed', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('skip_special_tokens', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_gpu', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_tool_filter', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('assign_names', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_datetime', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_system_instructions', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_guardrails', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_mood', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('use_personality', existing_type=sa.Boolean(), type_=sa.NUMERIC(), existing_nullable=True)
            batch_op.alter_column('botname', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=True)
            batch_op.alter_column('name', existing_type=sa.String(), type_=sa.TEXT(), existing_nullable=True)
    else:
        # PostgreSQL and other databases
        op.alter_column('image_filter_values', 'max_value',
                   existing_type=sa.Float(),
                   type_=sa.REAL(),
                   existing_nullable=True)
        op.alter_column('image_filter_values', 'min_value',
                   existing_type=sa.Float(),
                   type_=sa.REAL(),
                   existing_nullable=True)
        op.alter_column('image_filter_values', 'value_type',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=False)
        op.alter_column('image_filter_values', 'value',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=False)
        op.alter_column('image_filter_values', 'name',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=False)
        op.alter_column('chatbots', 'use_weather_prompt',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_backstory',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_cache',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'early_stopping',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'do_sample',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'return_result',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'dtype',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'model_type',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'model_version',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'random_seed',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'skip_special_tokens',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_gpu',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_tool_filter',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'assign_names',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_datetime',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_system_instructions',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_guardrails',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_mood',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'use_personality',
                   existing_type=sa.Boolean(),
                   type_=sa.NUMERIC(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'botname',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=True)
        op.alter_column('chatbots', 'name',
                   existing_type=sa.String(),
                   type_=sa.TEXT(),
                   existing_nullable=True)
    # ### end Alembic commands ###
