"""add index to log script

Revision ID: 4650a36b9e03
Revises: c0901782fe23
Create Date: 2025-02-17 14:28:22.070906

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "4650a36b9e03"
down_revision = "c0901782fe23"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("ai_course_lesson_attendscript", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attendscript_attend_id"),
            ["attend_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attendscript_course_id"),
            ["course_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attendscript_lesson_id"),
            ["lesson_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attendscript_script_id"),
            ["script_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attendscript_user_id"),
            ["user_id"],
            unique=False,
        )

    with op.batch_alter_table("profile_item", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column(
                "profile_color_setting",
                sa.String(length=255),
                nullable=False,
                comment="Profile color",
            )
        )
        batch_op.add_column(
            sa.Column(
                "profile_check_prompt",
                sa.Text(),
                nullable=False,
                comment="Profile check prompt",
            )
        )
        batch_op.add_column(
            sa.Column("profile_check_model", sa.String(length=255), nullable=False)
        )
        batch_op.add_column(
            sa.Column(
                "profile_check_model_args",
                sa.Text(),
                nullable=False,
                comment="Profile check model args",
            )
        )
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_value_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_show_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )

    with op.batch_alter_table("profile_item_i18n", schema=None) as batch_op:
        batch_op.alter_column(
            "conf_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
            existing_server_default=sa.text("'0'"),
        )

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
            existing_server_default=sa.text("'0'"),
        )

    with op.batch_alter_table("profile_item_i18n", schema=None) as batch_op:
        batch_op.alter_column(
            "conf_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )

    with op.batch_alter_table("profile_item", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_show_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_value_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )
        batch_op.drop_column("profile_check_model_args")
        batch_op.drop_column("profile_check_model")
        batch_op.drop_column("profile_check_prompt")
        batch_op.drop_column("profile_color_setting")

    with op.batch_alter_table("ai_course_lesson_attendscript", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attendscript_user_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attendscript_script_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attendscript_lesson_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attendscript_course_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attendscript_attend_id"))

    # ### end Alembic commands ###
