"""update mysql to migrate version

Revision ID: ca7e9533368b
Revises: 31f18de7e03e
Create Date: 2025-08-17 07:59:34.342223

"""

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

# revision identifiers, used by Alembic.
revision = "ca7e9533368b"
down_revision = "31f18de7e03e"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("active_user_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_course", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_course_auth", schema=None) as batch_op:
        batch_op.alter_column(
            "created_at",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Creation time",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "updated_at",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_course_buy_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_course_lesson_attend", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_course_lesson_attendscript", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_lesson", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "status",
            existing_type=mysql.INTEGER(),
            comment="Status of the lesson: 0-delete ,1-publish,2-draft",
            existing_comment="Status of the lesson",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_lesson_script", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )
        batch_op.drop_index("ix_ai_lesson_script_lesson_status_idx")
        batch_op.drop_index("ix_ai_lesson_script_script_id")

    with op.batch_alter_table("discount_record", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("order_banner_info", schema=None) as batch_op:
        batch_op.alter_column(
            "id",
            existing_type=mysql.BIGINT(),
            comment="Unique ID",
            existing_nullable=False,
            autoincrement=True,
        )

    with op.batch_alter_table("pingxx_order", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("profile_item", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(),
            comment="profile type: 2900=input_unconf, 2901=input_text, 2902=input_number, 2903=input_select, 2904=input_sex, 2905=input_date",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_value_type",
            existing_type=mysql.INTEGER(),
            comment="profile value type: 3001=all, 3002=specific",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_show_type",
            existing_type=mysql.INTEGER(),
            comment="profile show type: 3001=all, 3002=user, 3003=course, 3004=hidden",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_prompt_type",
            existing_type=mysql.INTEGER(),
            comment="profile prompt type: 3101=profile, 3102=item",
            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(),
            comment="profile conf type: 3101=profile, 3102=item",
            existing_nullable=False,
        )

    with op.batch_alter_table("risk_control_result", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_conversion", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_feedback", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "is_admin",
            existing_type=mysql.TINYINT(display_width=1),
            server_default=None,
            existing_comment="is admin",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "is_creator",
            existing_type=mysql.TINYINT(display_width=1),
            server_default=None,
            existing_comment="is creator",
            existing_nullable=False,
        )
        batch_op.drop_column("password_hash")

    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(),
            server_default=None,
            comment="profile type: 2900=input_unconf, 2901=input_text, 2902=input_number, 2903=input_select, 2904=input_sex, 2905=input_date",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_token", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=None,
            existing_comment="Update time",
            existing_nullable=False,
        )

    # ### 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(),
            server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
            existing_comment="Update time",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(),
            server_default=sa.text("'0'"),
            comment=None,
            existing_comment="profile type: 2900=input_unconf, 2901=input_text, 2902=input_number, 2903=input_select, 2904=input_sex, 2905=input_date",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column(
                "password_hash",
                mysql.VARCHAR(length=255),
                nullable=False,
                comment="Hashed password",
            )
        )
        batch_op.alter_column(
            "is_creator",
            existing_type=mysql.TINYINT(display_width=1),
            server_default=sa.text("'0'"),
            existing_comment="is creator",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "is_admin",
            existing_type=mysql.TINYINT(display_width=1),
            server_default=sa.text("'0'"),
            existing_comment="is admin",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
            existing_comment="Update time",
            existing_nullable=False,
        )

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

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

    with op.batch_alter_table("risk_control_result", schema=None) as batch_op:
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
            existing_comment="Update time",
            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(),
            comment=None,
            existing_comment="profile conf type: 3101=profile, 3102=item",
            existing_nullable=False,
        )

    with op.batch_alter_table("profile_item", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_prompt_type",
            existing_type=mysql.INTEGER(),
            comment=None,
            existing_comment="profile prompt type: 3101=profile, 3102=item",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_show_type",
            existing_type=mysql.INTEGER(),
            comment=None,
            existing_comment="profile show type: 3001=all, 3002=user, 3003=course, 3004=hidden",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_value_type",
            existing_type=mysql.INTEGER(),
            comment=None,
            existing_comment="profile value type: 3001=all, 3002=specific",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(),
            comment=None,
            existing_comment="profile type: 2900=input_unconf, 2901=input_text, 2902=input_number, 2903=input_select, 2904=input_sex, 2905=input_date",
            existing_nullable=False,
        )

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

    with op.batch_alter_table("order_banner_info", schema=None) as batch_op:
        batch_op.alter_column(
            "id",
            existing_type=mysql.BIGINT(),
            comment=None,
            existing_comment="Unique ID",
            existing_nullable=False,
            autoincrement=True,
        )

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

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

    with op.batch_alter_table("ai_lesson_script", schema=None) as batch_op:
        batch_op.create_index(
            "ix_ai_lesson_script_script_id", ["script_index"], unique=False
        )
        batch_op.create_index(
            "ix_ai_lesson_script_lesson_status_idx",
            ["lesson_id", "status", "script_index"],
            unique=False,
        )
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
            existing_comment="Update time",
            existing_nullable=False,
        )

    with op.batch_alter_table("ai_lesson", schema=None) as batch_op:
        batch_op.alter_column(
            "status",
            existing_type=mysql.INTEGER(),
            comment="Status of the lesson",
            existing_comment="Status of the lesson: 0-delete ,1-publish,2-draft",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "updated",
            existing_type=mysql.TIMESTAMP(),
            server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
            existing_comment="Update time",
            existing_nullable=False,
        )

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

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

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

    with op.batch_alter_table("ai_course_auth", schema=None) as batch_op:
        batch_op.alter_column(
            "updated_at",
            existing_type=mysql.TIMESTAMP(),
            server_default=sa.text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"),
            existing_comment="Update time",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "created_at",
            existing_type=mysql.TIMESTAMP(),
            server_default=sa.text("CURRENT_TIMESTAMP"),
            existing_comment="Creation time",
            existing_nullable=False,
        )

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

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

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

    # ### end Alembic commands ###
