"""init dialectlist

迁移 ID: 506cbd6bf1ec
父迁移: f7a853b48636
创建时间: 2025-04-20 08:35:53.637761

"""

from __future__ import annotations

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

revision: str = "506cbd6bf1ec"
down_revision: str | Sequence[str] | None = "f7a853b48636"
branch_labels: str | Sequence[str] | None = None
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_dialectlist_messagecountcache",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("time", sa.DateTime(), nullable=False),
        sa.Column("session_id", sa.Integer(), nullable=False),
        sa.Column("session_bnum", sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint(
            "id", name=op.f("pk_nonebot_plugin_dialectlist_messagecountcache")
        ),
        info={"bind_key": "nonebot_plugin_dialectlist"},
    )
    with op.batch_alter_table(
        "nonebot_plugin_dialectlist_messagecountcache", schema=None
    ) as batch_op:
        batch_op.create_index(
            batch_op.f("ix_nonebot_plugin_dialectlist_messagecountcache_session_id"),
            ["session_id"],
            unique=False,
        )

    with op.batch_alter_table("model_messagecountcache", schema=None) as batch_op:
        batch_op.drop_index("ix_model_messagecountcache_session_id")

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


def downgrade(name: str = "") -> None:
    if name:
        return
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "model_messagecountcache",
        sa.Column("id", sa.INTEGER(), nullable=False),
        sa.Column("time", sa.DATETIME(), nullable=False),
        sa.Column("session_id", sa.INTEGER(), nullable=False),
        sa.Column("session_bnum", sa.INTEGER(), nullable=False),
        sa.PrimaryKeyConstraint("id", name="pk_model_messagecountcache"),
    )
    with op.batch_alter_table("model_messagecountcache", schema=None) as batch_op:
        batch_op.create_index(
            "ix_model_messagecountcache_session_id", ["session_id"], unique=False
        )

    with op.batch_alter_table(
        "nonebot_plugin_dialectlist_messagecountcache", schema=None
    ) as batch_op:
        batch_op.drop_index(
            batch_op.f("ix_nonebot_plugin_dialectlist_messagecountcache_session_id")
        )

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