"""fix not null columns

Revision ID: 7802f91665d9
Revises: 27c6c721706c
Create Date: 2025-03-04 10:00:24.725742

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '7802f91665d9'
down_revision: Union[str, None] = '27c6c721706c'
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('id', existing_type=sa.INTEGER(), nullable=False, autoincrement=True)
        
        with op.batch_alter_table('image_filter_values') as batch_op:
            batch_op.alter_column('id', existing_type=sa.INTEGER(), nullable=False, autoincrement=True)
            batch_op.alter_column('name', existing_type=sa.TEXT(), nullable=False)
            batch_op.alter_column('value', existing_type=sa.TEXT(), nullable=False)
            batch_op.alter_column('value_type', existing_type=sa.TEXT(), nullable=False)
    else:
        # PostgreSQL and other databases
        op.alter_column('chatbots', 'id',
                   existing_type=sa.INTEGER(),
                   nullable=False,
                   autoincrement=True)
        op.alter_column('image_filter_values', 'id',
                   existing_type=sa.INTEGER(),
                   nullable=False,
                   autoincrement=True)
        op.alter_column('image_filter_values', 'name',
                   existing_type=sa.TEXT(),
                   nullable=False)
        op.alter_column('image_filter_values', 'value',
                   existing_type=sa.TEXT(),
                   nullable=False)
        op.alter_column('image_filter_values', 'value_type',
                   existing_type=sa.TEXT(),
                   nullable=False)
    # ### 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('value_type', existing_type=sa.TEXT(), nullable=True)
            batch_op.alter_column('value', existing_type=sa.TEXT(), nullable=True)
            batch_op.alter_column('name', existing_type=sa.TEXT(), nullable=True)
            batch_op.alter_column('id', existing_type=sa.INTEGER(), nullable=True, autoincrement=True)
        
        with op.batch_alter_table('chatbots') as batch_op:
            batch_op.alter_column('id', existing_type=sa.INTEGER(), nullable=True, autoincrement=True)
    else:
        # PostgreSQL and other databases
        op.alter_column('image_filter_values', 'value_type',
                   existing_type=sa.TEXT(),
                   nullable=True)
        op.alter_column('image_filter_values', 'value',
                   existing_type=sa.TEXT(),
                   nullable=True)
        op.alter_column('image_filter_values', 'name',
                   existing_type=sa.TEXT(),
                   nullable=True)
        op.alter_column('image_filter_values', 'id',
                   existing_type=sa.INTEGER(),
                   nullable=True,
                   autoincrement=True)
        op.alter_column('chatbots', 'id',
                   existing_type=sa.INTEGER(),
                   nullable=True,
                   autoincrement=True)
    # ### end Alembic commands ###
