"""add index

Revision ID: 35619240774c
Revises: 84c9d43ae780
Create Date: 2025-02-04 07:57:26.720701

"""

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

# revision identifiers, used by Alembic.
revision = "35619240774c"
down_revision = "84c9d43ae780"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("active", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("active_user_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("admin_info", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("ai_course", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_course_id"), ["course_id"], unique=False
        )

    with op.batch_alter_table("ai_course_buy_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_buy_record_course_id"), ["course_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_buy_record_record_id"), ["record_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_buy_record_user_id"), ["user_id"], unique=False
        )

    with op.batch_alter_table("ai_course_lesson_attend", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attend_attend_id"),
            ["attend_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attend_course_id"),
            ["course_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attend_lesson_id"),
            ["lesson_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attend_script_unique_id"),
            ["script_unique_id"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attend_status"), ["status"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_ai_course_lesson_attend_user_id"), ["user_id"], unique=False
        )

    with op.batch_alter_table("ai_course_lesson_attendscript", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("ai_lesson", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )
        batch_op.create_index(
            batch_op.f("ix_ai_lesson_course_id"), ["course_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_ai_lesson_lesson_id"), ["lesson_id"], unique=False
        )

    with op.batch_alter_table("ai_lesson_script", schema=None) as batch_op:
        batch_op.alter_column(
            "ask_prompt",
            existing_type=mysql.INTEGER(display_width=11),
            type_=sa.Text(),
            existing_comment="Ask count history",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("discount", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("discount_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("pingxx_order", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("risk_control_result", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_conversion", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_feedback", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_token", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("user_token", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_feedback", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("user_conversion", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("risk_control_result", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("pingxx_order", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("discount_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("discount", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("ai_lesson_script", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )
        batch_op.alter_column(
            "ask_prompt",
            existing_type=sa.Text(),
            type_=mysql.INTEGER(display_width=11),
            existing_comment="Ask count history",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_lesson", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_ai_lesson_lesson_id"))
        batch_op.drop_index(batch_op.f("ix_ai_lesson_course_id"))
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("ai_course_lesson_attendscript", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("ai_course_lesson_attend", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attend_user_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attend_status"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attend_script_unique_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attend_lesson_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attend_course_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_lesson_attend_attend_id"))
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("ai_course_buy_record", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_ai_course_buy_record_user_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_buy_record_record_id"))
        batch_op.drop_index(batch_op.f("ix_ai_course_buy_record_course_id"))
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("ai_course", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_ai_course_course_id"))
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("admin_info", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("active_user_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    with op.batch_alter_table("active", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            comment=None,
            existing_comment="Update time",
            existing_nullable=False,
            existing_server_default=sa.text(
                "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
            ),
        )

    # ### end Alembic commands ###
