"""first revision

迁移 ID: 6a6a44d58ced
父迁移:
创建时间: 2025-11-27 20:39:11.240822

"""

from __future__ import annotations

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

revision: str = "6a6a44d58ced"
down_revision: str | Sequence[str] | None = None
branch_labels: str | Sequence[str] | None = ("nonebot_plugin_ai_groupmate",)
depends_on: str | Sequence[str] | None = None


def upgrade(name: str = "") -> None:
    if name:
        return
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "nonebot_plugin_ai_groupmate_chathistory",
        sa.Column("msg_id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("session_id", sa.String(), nullable=False),
        sa.Column("user_id", sa.String(), nullable=False),
        sa.Column("content_type", sa.String(), nullable=False),
        sa.Column("content", sa.String(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("user_name", sa.String(), nullable=False),
        sa.Column("media_id", sa.Integer(), nullable=True),
        sa.Column("vectorized", sa.Boolean(), nullable=False),
        sa.PrimaryKeyConstraint("msg_id", name=op.f("pk_nonebot_plugin_ai_groupmate_chathistory")),
        info={"bind_key": "nonebot_plugin_ai_groupmate"},
    )
    with op.batch_alter_table("nonebot_plugin_ai_groupmate_chathistory", schema=None) as batch_op:
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_created_at"), ["created_at"], unique=False)
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_session_id"), ["session_id"], unique=False)
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_user_id"), ["user_id"], unique=False)
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_vectorized"), ["vectorized"], unique=False)

    op.create_table(
        "nonebot_plugin_ai_groupmate_mediastorage",
        sa.Column("media_id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("file_hash", sa.String(length=64), nullable=False),
        sa.Column("file_path", sa.String(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("references", sa.Integer(), nullable=False),
        sa.Column("description", sa.String(), nullable=False),
        sa.Column("vectorized", sa.Boolean(), nullable=False),
        sa.PrimaryKeyConstraint("media_id", name=op.f("pk_nonebot_plugin_ai_groupmate_mediastorage")),
        sa.UniqueConstraint("file_hash"),
        info={"bind_key": "nonebot_plugin_ai_groupmate"},
    )
    with op.batch_alter_table("nonebot_plugin_ai_groupmate_mediastorage", schema=None) as batch_op:
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_mediastorage_created_at"), ["created_at"], unique=False)
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_mediastorage_references"), ["references"], unique=False)
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_mediastorage_vectorized"), ["vectorized"], unique=False)

    op.create_table(
        "nonebot_plugin_ai_groupmate_userrelation",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("user_id", sa.String(), nullable=False),
        sa.Column("user_name", sa.String(), nullable=False),
        sa.Column("favorability", sa.Integer(), nullable=False),
        sa.Column("tags", sa.JSON(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_nonebot_plugin_ai_groupmate_userrelation")),
        info={"bind_key": "nonebot_plugin_ai_groupmate"},
    )
    with op.batch_alter_table("nonebot_plugin_ai_groupmate_userrelation", schema=None) as batch_op:
        batch_op.create_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_userrelation_user_id"), ["user_id"], unique=False)

    # ### end Alembic commands ###


def downgrade(name: str = "") -> None:
    if name:
        return
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("nonebot_plugin_ai_groupmate_userrelation", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_userrelation_user_id"))

    op.drop_table("nonebot_plugin_ai_groupmate_userrelation")
    with op.batch_alter_table("nonebot_plugin_ai_groupmate_mediastorage", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_mediastorage_vectorized"))
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_mediastorage_references"))
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_mediastorage_created_at"))

    op.drop_table("nonebot_plugin_ai_groupmate_mediastorage")
    with op.batch_alter_table("nonebot_plugin_ai_groupmate_chathistory", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_vectorized"))
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_user_id"))
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_session_id"))
        batch_op.drop_index(batch_op.f("ix_nonebot_plugin_ai_groupmate_chathistory_created_at"))

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