"""Recreate HistoricalData

迁移 ID: 9f6582279ce2
父迁移: 9cd1647db502
创建时间: 2023-11-21 08:35:50.393246

"""

from __future__ import annotations

from typing import TYPE_CHECKING

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

if TYPE_CHECKING:
    from collections.abc import Sequence

revision: str = '9f6582279ce2'
down_revision: str | Sequence[str] | None = '9cd1647db502'
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! ###
    with op.batch_alter_table('nonebot_plugin_tetris_stats_historicaldata', schema=None) as batch_op:
        batch_op.drop_index('ix_nonebot_plugin_tetris_stats_historicaldata_command_type')
        batch_op.drop_index('ix_nonebot_plugin_tetris_stats_historicaldata_game_platform')
        batch_op.drop_index('ix_nonebot_plugin_tetris_stats_historicaldata_source_account')
        batch_op.drop_index('ix_nonebot_plugin_tetris_stats_historicaldata_source_type')

    op.drop_table('nonebot_plugin_tetris_stats_historicaldata')

    op.create_table(
        'nonebot_plugin_tetris_stats_historicaldata',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('trigger_time', sa.DateTime(), nullable=False),
        sa.Column('bot_platform', sa.String(length=32), nullable=True),
        sa.Column('bot_account', sa.String(), nullable=True),
        sa.Column('source_type', sa.String(length=32), nullable=True),
        sa.Column('source_account', sa.String(), nullable=True),
        sa.Column('message', sa.PickleType(), nullable=True),
        sa.Column('game_platform', sa.String(length=32), nullable=False),
        sa.Column('command_type', sa.String(length=16), nullable=False),
        sa.Column('command_args', sa.JSON(), nullable=False),
        sa.Column('game_user', sa.JSON(), nullable=False),
        sa.Column('processed_data', sa.JSON(), nullable=False),
        sa.Column('finish_time', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_nonebot_plugin_tetris_stats_historicaldata')),
    )
    with op.batch_alter_table('nonebot_plugin_tetris_stats_historicaldata', schema=None) as batch_op:
        batch_op.create_index(
            batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_command_type'), ['command_type'], unique=False
        )
        batch_op.create_index(
            batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_game_platform'), ['game_platform'], unique=False
        )
        batch_op.create_index(
            batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_source_account'), ['source_account'], unique=False
        )
        batch_op.create_index(
            batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_source_type'), ['source_type'], 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_tetris_stats_historicaldata', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_source_type'))
        batch_op.drop_index(batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_source_account'))
        batch_op.drop_index(batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_game_platform'))
        batch_op.drop_index(batch_op.f('ix_nonebot_plugin_tetris_stats_historicaldata_command_type'))

    op.drop_table('nonebot_plugin_tetris_stats_historicaldata')

    op.create_table(
        'nonebot_plugin_tetris_stats_historicaldata',
        sa.Column('id', sa.INTEGER(), nullable=False),
        sa.Column('trigger_time', sa.DATETIME(), nullable=False),
        sa.Column('bot_platform', sa.VARCHAR(length=32), nullable=True),
        sa.Column('bot_account', sa.VARCHAR(), nullable=True),
        sa.Column('source_type', sa.VARCHAR(length=32), nullable=True),
        sa.Column('source_account', sa.VARCHAR(), nullable=True),
        sa.Column('message', sa.BLOB(), nullable=True),
        sa.Column('game_platform', sa.VARCHAR(length=32), nullable=False),
        sa.Column('command_type', sa.VARCHAR(length=16), nullable=False),
        sa.Column('command_args', sqlite.JSON(), nullable=False),
        sa.Column('game_user', sa.BLOB(), nullable=False),
        sa.Column('processed_data', sa.BLOB(), nullable=False),
        sa.Column('finish_time', sa.DATETIME(), nullable=False),
        sa.PrimaryKeyConstraint('id', name='pk_nonebot_plugin_tetris_stats_historicaldata'),
    )
    with op.batch_alter_table('nonebot_plugin_tetris_stats_historicaldata', schema=None) as batch_op:
        batch_op.create_index(
            'ix_nonebot_plugin_tetris_stats_historicaldata_source_type', ['source_type'], unique=False
        )
        batch_op.create_index(
            'ix_nonebot_plugin_tetris_stats_historicaldata_source_account', ['source_account'], unique=False
        )
        batch_op.create_index(
            'ix_nonebot_plugin_tetris_stats_historicaldata_game_platform', ['game_platform'], unique=False
        )
        batch_op.create_index(
            'ix_nonebot_plugin_tetris_stats_historicaldata_command_type', ['command_type'], unique=False
        )

    # ### end Alembic commands ###
