"""init database  tables

Revision ID: 75ce6807f5e5
Revises:
Create Date: 2024-10-23 05:35:00.366247

"""

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

# revision identifiers, used by Alembic.
revision = "75ce6807f5e5"
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "active",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "active_id", sa.String(length=36), nullable=False, comment="Active UUID"
        ),
        sa.Column(
            "active_name", sa.String(length=255), nullable=False, comment="Active name"
        ),
        sa.Column(
            "active_desc", sa.Text(), nullable=False, comment="Active description"
        ),
        sa.Column("active_type", sa.Integer(), nullable=False, comment="Active type"),
        sa.Column(
            "active_status", sa.Integer(), nullable=False, comment="Active status"
        ),
        sa.Column(
            "active_start_time",
            sa.DateTime(),
            nullable=False,
            comment="Active start time",
        ),
        sa.Column(
            "active_end_time", sa.DateTime(), nullable=False, comment="Active end time"
        ),
        sa.Column(
            "active_price",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Active price",
        ),
        sa.Column(
            "active_discount",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Active discount",
        ),
        sa.Column(
            "active_discount_type",
            sa.Integer(),
            nullable=False,
            comment="Active discount type",
        ),
        sa.Column(
            "active_discount_desc",
            sa.Text(),
            nullable=False,
            comment="Active discount description",
        ),
        sa.Column("active_filter", sa.Text(), nullable=False, comment="Active filter"),
        sa.Column(
            "active_course",
            sa.String(length=36),
            nullable=False,
            comment="Active course",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    with op.batch_alter_table("active", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_active_active_end_time"), ["active_end_time"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_active_active_start_time"),
            ["active_start_time"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_active_active_status"), ["active_status"], unique=False
        )

    op.create_table(
        "active_user_record",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "record_id", sa.String(length=36), nullable=False, comment="Record UUID"
        ),
        sa.Column(
            "active_id", sa.String(length=36), nullable=False, comment="Active UUID"
        ),
        sa.Column(
            "active_name", sa.String(length=255), nullable=False, comment="Active name"
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "price",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Price of the active",
        ),
        sa.Column(
            "order_id", sa.String(length=36), nullable=False, comment="Order UUID"
        ),
        sa.Column(
            "status", sa.Integer(), nullable=False, comment="Status of the record"
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "admin_info",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "username", sa.String(length=255), nullable=False, comment="Login username"
        ),
        sa.Column(
            "name", sa.String(length=255), nullable=False, comment="User real name"
        ),
        sa.Column(
            "password_hash",
            sa.String(length=255),
            nullable=False,
            comment="Hashed password",
        ),
        sa.Column("email", sa.String(length=255), nullable=False, comment="Email"),
        sa.Column("mobile", sa.String(length=20), nullable=False, comment="Mobile"),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "default_model",
            sa.String(length=255),
            nullable=False,
            comment="Default model",
        ),
        sa.Column("user_state", sa.Integer(), nullable=True, comment="User_state"),
        sa.Column("user_sex", sa.Integer(), nullable=True, comment="user sex"),
        sa.Column("user_birth", sa.Date(), nullable=True, comment="user birth"),
        sa.Column(
            "user_avatar", sa.String(length=255), nullable=True, comment="user avatar"
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "ai_course",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
        ),
        sa.Column(
            "course_id", sa.String(length=36), nullable=False, comment="Course UUID"
        ),
        sa.Column(
            "course_name", sa.String(length=255), nullable=False, comment="Course name"
        ),
        sa.Column(
            "course_desc", sa.Text(), nullable=False, comment="Course description"
        ),
        sa.Column(
            "course_price",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Course price",
        ),
        sa.Column(
            "course_status", sa.Integer(), nullable=False, comment="Course status"
        ),
        sa.Column(
            "course_feishu_id",
            sa.String(length=255),
            nullable=False,
            comment="Course feishu ID",
        ),
        sa.Column(
            "course_teacher_avator",
            sa.String(length=255),
            nullable=False,
            comment="Course teacher avatar",
        ),
        sa.Column(
            "course_default_model",
            sa.String(length=255),
            nullable=False,
            comment="Course default model",
        ),
        sa.Column(
            "course_language",
            sa.String(length=255),
            nullable=False,
            comment="Course language",
        ),
        sa.Column(
            "course_name_multi_language",
            sa.Text(),
            nullable=False,
            comment="Course multi language",
        ),
        sa.Column(
            "ask_count_limit", sa.Integer(), nullable=False, comment="Ask count limit"
        ),
        sa.Column(
            "ask_model",
            sa.String(length=255),
            nullable=False,
            comment="Ask count model",
        ),
        sa.Column("ask_prompt", sa.Text(), nullable=False, comment="Ask Prompt"),
        sa.Column(
            "ask_with_history",
            sa.Integer(),
            nullable=False,
            comment="Ask with history Count",
        ),
        sa.Column("ask_mode", sa.Integer(), nullable=False, comment="Ask mode"),
        sa.Column(
            "created_user_id",
            sa.String(length=36),
            nullable=True,
            comment="created user ID",
        ),
        sa.Column(
            "updated_user_id",
            sa.String(length=36),
            nullable=True,
            comment="updated user ID",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "status", sa.Integer(), nullable=False, comment="Status of the course"
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "ai_course_buy_record",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "record_id", sa.String(length=36), nullable=False, comment="Record UUID"
        ),
        sa.Column(
            "course_id", sa.String(length=36), nullable=False, comment="Course UUID"
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "price",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Price of the course",
        ),
        sa.Column(
            "pay_value",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Payment value",
        ),
        sa.Column(
            "discount_value",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Discount value",
        ),
        sa.Column(
            "paid_value",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Paid value",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "status", sa.Integer(), nullable=False, comment="Status of the record"
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "ai_course_lesson_attend",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "attend_id", sa.String(length=36), nullable=False, comment="Attend UUID"
        ),
        sa.Column(
            "lesson_id", sa.String(length=36), nullable=False, comment="Lesson UUID"
        ),
        sa.Column(
            "course_id", sa.String(length=36), nullable=False, comment="Course UUID"
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "status",
            sa.Integer(),
            nullable=False,
            comment="Status of the attend: 0-not started, 1-in progress, 2-completed",
        ),
        sa.Column(
            "script_index",
            sa.Integer(),
            nullable=False,
            comment="Status of the attend: 0-not started, 1-in progress, 2-completed",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "ai_course_lesson_attend_association",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "association_id",
            sa.String(length=36),
            nullable=False,
            comment="Attend UUID",
        ),
        sa.Column(
            "from_attend_id",
            sa.String(length=36),
            nullable=False,
            comment="Attend UUID",
        ),
        sa.Column(
            "to_attend_id", sa.String(length=36), nullable=False, comment="Attend UUID"
        ),
        sa.Column(
            "user_id", sa.String(length=36), nullable=False, comment="Attend UUID"
        ),
        sa.Column(
            "association_status",
            sa.Integer(),
            nullable=False,
            comment="Status of the attend: 0-not started, 1-in progress, 2-completed",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "ai_course_lesson_attendscript",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("log_id", sa.String(length=36), nullable=False, comment="Log UUID"),
        sa.Column(
            "attend_id", sa.String(length=36), nullable=False, comment="Attend UUID"
        ),
        sa.Column(
            "script_id", sa.String(length=36), nullable=False, comment="Script UUID"
        ),
        sa.Column(
            "lesson_id", sa.String(length=36), nullable=False, comment="Lesson UUID"
        ),
        sa.Column(
            "course_id", sa.String(length=36), nullable=False, comment="Course UUID"
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column("script_index", sa.Integer(), nullable=False, comment="Script index"),
        sa.Column("script_role", sa.Integer(), nullable=False, comment="Script role"),
        sa.Column(
            "script_content", sa.Text(), nullable=False, comment="Script content"
        ),
        sa.Column(
            "status", sa.Integer(), nullable=False, comment="Status of the attend"
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    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_log_id"),
            ["log_id"],
            unique=False,
        )

    op.create_table(
        "ai_lesson",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
        ),
        sa.Column(
            "lesson_id", sa.String(length=36), nullable=False, comment="Lesson UUID"
        ),
        sa.Column(
            "course_id", sa.String(length=36), nullable=False, comment="Course UUID"
        ),
        sa.Column(
            "lesson_name", sa.String(length=255), nullable=False, comment="Lesson name"
        ),
        sa.Column(
            "lesson_desc", sa.Text(), nullable=False, comment="Lesson description"
        ),
        sa.Column(
            "lesson_no", sa.String(length=32), nullable=True, comment="Lesson number"
        ),
        sa.Column("lesson_index", sa.Integer(), nullable=False, comment="Lesson index"),
        sa.Column(
            "lesson_feishu_id",
            sa.String(length=255),
            nullable=False,
            comment="Lesson feishu ID",
        ),
        sa.Column(
            "lesson_status", sa.Integer(), nullable=False, comment="Lesson status"
        ),
        sa.Column("lesson_type", sa.Integer(), nullable=False, comment="Lesson type"),
        sa.Column(
            "lesson_summary", sa.Text(), nullable=False, comment="Lesson summary"
        ),
        sa.Column(
            "lesson_language",
            sa.String(length=255),
            nullable=False,
            comment="Lesson language",
        ),
        sa.Column(
            "lesson_name_multi_language",
            sa.Text(),
            nullable=False,
            comment="Lesson multi language",
        ),
        sa.Column(
            "ask_count_limit", sa.Integer(), nullable=False, comment="Ask count limit"
        ),
        sa.Column(
            "ask_model",
            sa.String(length=255),
            nullable=False,
            comment="Ask count model",
        ),
        sa.Column("ask_prompt", sa.Text(), nullable=False, comment="Ask Prompt"),
        sa.Column(
            "ask_with_history",
            sa.Integer(),
            nullable=False,
            comment="Ask with history Count",
        ),
        sa.Column("ask_mode", sa.Integer(), nullable=False, comment="Ask mode"),
        sa.Column(
            "pre_lesson_no",
            sa.String(length=255),
            nullable=False,
            comment="pre_lesson_no",
        ),
        sa.Column(
            "created_user_id",
            sa.String(length=36),
            nullable=True,
            comment="created user ID",
        ),
        sa.Column(
            "updated_user_id",
            sa.String(length=36),
            nullable=True,
            comment="updated user ID",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "status", sa.Integer(), nullable=False, comment="Status of the lesson"
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "ai_lesson_script",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "script_id", sa.String(length=36), nullable=False, comment="Script UUID"
        ),
        sa.Column(
            "lesson_id", sa.String(length=36), nullable=False, comment="Lesson UUID"
        ),
        sa.Column(
            "script_name", sa.String(length=255), nullable=False, comment="Script name"
        ),
        sa.Column(
            "script_desc", sa.Text(), nullable=False, comment="Script description"
        ),
        sa.Column("script_index", sa.Integer(), nullable=False, comment="Script index"),
        sa.Column(
            "script_feishu_id",
            sa.String(length=255),
            nullable=False,
            comment="Script feishu ID",
        ),
        sa.Column(
            "script_version", sa.Integer(), nullable=False, comment="Script version"
        ),
        sa.Column("script_no", sa.Integer(), nullable=False, comment="Script number"),
        sa.Column("script_type", sa.Integer(), nullable=False, comment="Script type"),
        sa.Column(
            "script_content_type",
            sa.Integer(),
            nullable=False,
            comment="Script content type",
        ),
        sa.Column("script_prompt", sa.Text(), nullable=False, comment="Script prompt"),
        sa.Column(
            "script_model", sa.String(length=36), nullable=False, comment="Script model"
        ),
        sa.Column(
            "script_temprature",
            sa.DECIMAL(precision=10, scale=2),
            nullable=False,
            comment="Script Temprature",
        ),
        sa.Column(
            "script_profile", sa.Text(), nullable=False, comment="Script profile"
        ),
        sa.Column(
            "script_media_url", sa.Text(), nullable=False, comment="Script media URL"
        ),
        sa.Column(
            "script_ui_type", sa.Integer(), nullable=False, comment="Script UI type"
        ),
        sa.Column(
            "script_ui_content", sa.Text(), nullable=False, comment="Script UI content"
        ),
        sa.Column(
            "script_check_prompt",
            sa.Text(),
            nullable=False,
            comment="Script check prompt",
        ),
        sa.Column(
            "script_check_flag", sa.Text(), nullable=False, comment="Script check flag"
        ),
        sa.Column(
            "script_ui_profile", sa.Text(), nullable=False, comment="Script UI profile"
        ),
        sa.Column(
            "script_end_action", sa.Text(), nullable=False, comment="Script end action"
        ),
        sa.Column(
            "script_other_conf",
            sa.Text(),
            nullable=False,
            comment="Other configurations of the script",
        ),
        sa.Column(
            "ask_count_limit", sa.Integer(), nullable=False, comment="Ask count limit"
        ),
        sa.Column(
            "ask_model",
            sa.String(length=255),
            nullable=False,
            comment="Ask count model",
        ),
        sa.Column("ask_prompt", sa.Text(), nullable=False, comment="Ask count history"),
        sa.Column(
            "ask_with_history",
            sa.Integer(),
            nullable=False,
            comment="Ask with history Count",
        ),
        sa.Column("ask_mode", sa.Integer(), nullable=False, comment="Ask mode"),
        sa.Column(
            "created_user_id",
            sa.String(length=36),
            nullable=True,
            comment="created user ID",
        ),
        sa.Column(
            "updated_user_id",
            sa.String(length=36),
            nullable=True,
            comment="updated user ID",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "status", sa.Integer(), nullable=False, comment="Status of the script"
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "discount",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "discount_id", sa.String(length=36), nullable=False, comment="Discount UUID"
        ),
        sa.Column(
            "discount_code",
            sa.String(length=36),
            nullable=False,
            comment="Discount code",
        ),
        sa.Column(
            "discount_type",
            sa.Integer(),
            nullable=False,
            comment="Discount type: 701-fixed, 702-percent",
        ),
        sa.Column(
            "discount_apply_type",
            sa.Integer(),
            nullable=False,
            comment="Discount apply type: 801-all, 802-specific",
        ),
        sa.Column(
            "discount_value",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Discount value",
        ),
        sa.Column(
            "discount_limit",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Discount limit",
        ),
        sa.Column(
            "discount_start",
            sa.TIMESTAMP(),
            nullable=False,
            comment="Discount start time",
        ),
        sa.Column(
            "discount_end", sa.TIMESTAMP(), nullable=False, comment="Discount end time"
        ),
        sa.Column(
            "discount_channel",
            sa.String(length=36),
            nullable=False,
            comment="Discount channel",
        ),
        sa.Column(
            "discount_filter", sa.Text(), nullable=False, comment="Discount filter"
        ),
        sa.Column(
            "discount_count",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            nullable=False,
            comment="Discount count",
        ),
        sa.Column(
            "discount_used", mysql.BIGINT(), nullable=False, comment="Discount used"
        ),
        sa.Column(
            "discount_generated_user",
            sa.String(length=36),
            nullable=False,
            comment="Discount generated user",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "status",
            sa.Integer(),
            nullable=False,
            comment="Status of the discount: 0-inactive, 1-active",
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    with op.batch_alter_table("discount", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_discount_discount_code"), ["discount_code"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_discount_discount_id"), ["discount_id"], unique=False
        )

    op.create_table(
        "discount_record",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "record_id", sa.String(length=36), nullable=False, comment="Record UUID"
        ),
        sa.Column(
            "discount_id", sa.String(length=36), nullable=False, comment="Discount UUID"
        ),
        sa.Column(
            "discount_name",
            sa.String(length=255),
            nullable=False,
            comment="Discount name",
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "course_id", sa.String(length=36), nullable=False, comment="Course UUID"
        ),
        sa.Column(
            "order_id", sa.String(length=36), nullable=False, comment="Order UUID"
        ),
        sa.Column(
            "discount_code",
            sa.String(length=36),
            nullable=False,
            comment="Discount code",
        ),
        sa.Column(
            "discount_type",
            sa.Integer(),
            nullable=False,
            comment="Discount type: 0-percent, 1-amount",
        ),
        sa.Column(
            "discount_value",
            sa.Numeric(precision=10, scale=2),
            nullable=False,
            comment="Discount value",
        ),
        sa.Column(
            "status",
            sa.Integer(),
            nullable=False,
            comment="Status of the record: 0-inactive, 1-active",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    with op.batch_alter_table("discount_record", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_discount_record_course_id"), ["course_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_discount_record_discount_id"), ["discount_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_discount_record_order_id"), ["order_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_discount_record_record_id"), ["record_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_discount_record_user_id"), ["user_id"], unique=False
        )

    op.create_table(
        "pingxx_order",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column(
            "order_id", sa.String(length=36), nullable=False, comment="Order UUID"
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "course_id", sa.String(length=36), nullable=False, comment="Course UUID"
        ),
        sa.Column(
            "record_id", sa.String(length=36), nullable=False, comment="Record UUID"
        ),
        sa.Column(
            "pingxx_transaction_no",
            sa.String(length=36),
            nullable=False,
            comment="Pingxx transaction number",
        ),
        sa.Column(
            "pingxx_app_id",
            sa.String(length=36),
            nullable=False,
            comment="Pingxx app ID",
        ),
        sa.Column(
            "pingxx_channel",
            sa.String(length=36),
            nullable=False,
            comment="Payment channel",
        ),
        sa.Column(
            "pingxx_id", sa.String(length=36), nullable=False, comment="Pingxx ID"
        ),
        sa.Column(
            "channel", sa.String(length=36), nullable=False, comment="Payment channel"
        ),
        sa.Column("amount", mysql.BIGINT(), nullable=False, comment="Payment amount"),
        sa.Column("extra", sa.Text(), nullable=False, comment="Extra information"),
        sa.Column("currency", sa.String(length=36), nullable=False, comment="Currency"),
        sa.Column(
            "subject", sa.String(length=255), nullable=False, comment="Payment subject"
        ),
        sa.Column(
            "body", sa.String(length=255), nullable=False, comment="Payment body"
        ),
        sa.Column(
            "order_no", sa.String(length=255), nullable=False, comment="Order number"
        ),
        sa.Column(
            "client_ip", sa.String(length=255), nullable=False, comment="Client IP"
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "status",
            sa.Integer(),
            nullable=False,
            comment="Status of the order: 0-unpaid, 1-paid, 2-refunded, 3-closed, 4-failed",
        ),
        sa.Column(
            "charge_id", sa.String(length=255), nullable=False, comment="Charge ID"
        ),
        sa.Column("paid_at", sa.TIMESTAMP(), nullable=False, comment="Payment time"),
        sa.Column("refunded_at", sa.TIMESTAMP(), nullable=False, comment="Refund time"),
        sa.Column("closed_at", sa.TIMESTAMP(), nullable=False, comment="Close time"),
        sa.Column("failed_at", sa.TIMESTAMP(), nullable=False, comment="Failed time"),
        sa.Column(
            "refund_id", sa.String(length=255), nullable=False, comment="Refund ID"
        ),
        sa.Column(
            "failure_code",
            sa.String(length=255),
            nullable=False,
            comment="Failure code",
        ),
        sa.Column(
            "failure_msg",
            sa.String(length=255),
            nullable=False,
            comment="Failure message",
        ),
        sa.Column("charge_object", sa.Text(), nullable=False, comment="Charge object"),
        sa.PrimaryKeyConstraint("id"),
    )
    with op.batch_alter_table("pingxx_order", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_pingxx_order_course_id"), ["course_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_pingxx_order_order_id"), ["order_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_pingxx_order_pingxx_app_id"), ["pingxx_app_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_pingxx_order_pingxx_transaction_no"),
            ["pingxx_transaction_no"],
            unique=False,
        )
        batch_op.create_index(
            batch_op.f("ix_pingxx_order_record_id"), ["record_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_pingxx_order_user_id"), ["user_id"], unique=False
        )

    op.create_table(
        "risk_control_result",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("chat_id", sa.String(length=36), nullable=False, comment="Chat UUID"),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column("text", sa.Text(), nullable=False, comment="Text"),
        sa.Column(
            "check_vendor",
            sa.String(length=255),
            nullable=False,
            comment="Check vendor",
        ),
        sa.Column("check_result", sa.Integer(), nullable=False, comment="Check result"),
        sa.Column("check_resp", sa.Text(), nullable=False, comment="Check response"),
        sa.Column("is_pass", sa.Integer(), nullable=False, comment="Is pass"),
        sa.Column(
            "check_strategy",
            sa.String(length=30),
            nullable=False,
            comment="Check strategy",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "user_conversion",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "conversion_id",
            sa.String(length=36),
            nullable=False,
            comment="Conversion UUID",
        ),
        sa.Column(
            "conversion_source",
            sa.String(length=36),
            nullable=False,
            comment="Conversion type",
        ),
        sa.Column(
            "conversion_status",
            sa.Integer(),
            nullable=False,
            comment="Conversion state",
        ),
        sa.Column(
            "conversion_uuid",
            sa.String(length=36),
            nullable=False,
            comment="Conversion UUID",
        ),
        sa.Column(
            "conversion_third_platform",
            sa.String(length=255),
            nullable=False,
            comment="Conversion third platform",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "user_feedback",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "feedback", sa.String(length=300), nullable=False, comment="Feedback"
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "user_info",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "username", sa.String(length=255), nullable=False, comment="Login username"
        ),
        sa.Column(
            "name", sa.String(length=255), nullable=False, comment="User real name"
        ),
        sa.Column(
            "password_hash",
            sa.String(length=255),
            nullable=False,
            comment="Hashed password",
        ),
        sa.Column("email", sa.String(length=255), nullable=False, comment="Email"),
        sa.Column("mobile", sa.String(length=20), nullable=False, comment="Mobile"),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "default_model",
            sa.String(length=255),
            nullable=False,
            comment="Default model",
        ),
        sa.Column("user_state", sa.Integer(), nullable=True, comment="User_state"),
        sa.Column("user_sex", sa.Integer(), nullable=True, comment="user sex"),
        sa.Column("user_birth", sa.Date(), nullable=True, comment="user birth"),
        sa.Column(
            "user_avatar", sa.String(length=255), nullable=True, comment="user avatar"
        ),
        sa.Column(
            "user_open_id", sa.String(length=255), nullable=True, comment="user open id"
        ),
        sa.Column(
            "user_unicon_id",
            sa.String(length=255),
            nullable=True,
            comment="user unicon id",
        ),
        sa.Column(
            "user_language",
            sa.String(length=30),
            nullable=True,
            comment="user language",
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_user_info_mobile"), ["mobile"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_user_info_user_id"), ["user_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_user_info_user_open_id"), ["user_open_id"], unique=False
        )
        batch_op.create_index(
            batch_op.f("ix_user_info_user_unicon_id"), ["user_unicon_id"], unique=False
        )

    op.create_table(
        "user_profile",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column(
            "profile_key", sa.String(length=255), nullable=False, comment="Profile key"
        ),
        sa.Column("profile_value", sa.Text(), nullable=False, comment="Profile value"),
        sa.Column(
            "profile_type",
            sa.Integer(),
            nullable=False,
            comment="0 default, 1 system configuration, 2 user configuration, 3 course configuration",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.Column(
            "status",
            sa.Integer(),
            nullable=False,
            comment="0 for deleted, 1 for active",
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "user_token",
        sa.Column(
            "id",
            mysql.BIGINT().with_variant(Integer, "sqlite"),
            autoincrement=True,
            nullable=False,
            comment="Unique ID",
        ),
        sa.Column("user_id", sa.String(length=36), nullable=False, comment="User UUID"),
        sa.Column("token", sa.String(length=255), nullable=False, comment="Token"),
        sa.Column("token_type", sa.Integer(), nullable=False, comment="Token type"),
        sa.Column(
            "token_expired_at",
            sa.TIMESTAMP(),
            nullable=True,
            comment="Token expired time",
        ),
        sa.Column("created", sa.TIMESTAMP(), nullable=False, comment="Creation time"),
        sa.Column("updated", sa.TIMESTAMP(), nullable=False, comment="Update time"),
        sa.PrimaryKeyConstraint("id"),
    )
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("user_token")
    op.drop_table("user_profile")
    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_user_info_user_unicon_id"))
        batch_op.drop_index(batch_op.f("ix_user_info_user_open_id"))
        batch_op.drop_index(batch_op.f("ix_user_info_user_id"))
        batch_op.drop_index(batch_op.f("ix_user_info_mobile"))

    op.drop_table("user_info")
    op.drop_table("user_feedback")
    op.drop_table("user_conversion")
    op.drop_table("risk_control_result")
    with op.batch_alter_table("pingxx_order", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_pingxx_order_user_id"))
        batch_op.drop_index(batch_op.f("ix_pingxx_order_record_id"))
        batch_op.drop_index(batch_op.f("ix_pingxx_order_pingxx_transaction_no"))
        batch_op.drop_index(batch_op.f("ix_pingxx_order_pingxx_app_id"))
        batch_op.drop_index(batch_op.f("ix_pingxx_order_order_id"))
        batch_op.drop_index(batch_op.f("ix_pingxx_order_course_id"))

    op.drop_table("pingxx_order")
    with op.batch_alter_table("discount_record", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_discount_record_user_id"))
        batch_op.drop_index(batch_op.f("ix_discount_record_record_id"))
        batch_op.drop_index(batch_op.f("ix_discount_record_order_id"))
        batch_op.drop_index(batch_op.f("ix_discount_record_discount_id"))
        batch_op.drop_index(batch_op.f("ix_discount_record_course_id"))

    op.drop_table("discount_record")
    with op.batch_alter_table("discount", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_discount_discount_id"))
        batch_op.drop_index(batch_op.f("ix_discount_discount_code"))

    op.drop_table("discount")
    op.drop_table("ai_lesson_script")
    op.drop_table("ai_lesson")
    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_log_id"))

    op.drop_table("ai_course_lesson_attendscript")
    op.drop_table("ai_course_lesson_attend_association")
    op.drop_table("ai_course_lesson_attend")
    op.drop_table("ai_course_buy_record")
    op.drop_table("ai_course")
    op.drop_table("admin_info")
    op.drop_table("active_user_record")
    with op.batch_alter_table("active", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_active_active_status"))
        batch_op.drop_index(batch_op.f("ix_active_active_start_time"))
        batch_op.drop_index(batch_op.f("ix_active_active_end_time"))

    op.drop_table("active")
    # ### end Alembic commands ###
