From 429f99f77e8c6404a77e74e6602f0028be351072 Mon Sep 17 00:00:00 2001 From: shoucandanghehe Date: Fri, 9 Aug 2024 16:20:53 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20=E5=A2=9E=E5=8A=A0=20TE?= =?UTF-8?q?TRIOHistoricalData.api=5Ftype=20=E5=AD=97=E6=AE=B5=E9=95=BF?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...eab6961dce_extend_api_type_field_length.py | 50 +++++++++++++++++++ .../games/tetrio/api/models.py | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 nonebot_plugin_tetris_stats/config/migrations/cfeab6961dce_extend_api_type_field_length.py diff --git a/nonebot_plugin_tetris_stats/config/migrations/cfeab6961dce_extend_api_type_field_length.py b/nonebot_plugin_tetris_stats/config/migrations/cfeab6961dce_extend_api_type_field_length.py new file mode 100644 index 0000000..981f9a5 --- /dev/null +++ b/nonebot_plugin_tetris_stats/config/migrations/cfeab6961dce_extend_api_type_field_length.py @@ -0,0 +1,50 @@ +"""Extend api_type field length + +迁移 ID: cfeab6961dce +父迁移: f5b4a6d1325b +创建时间: 2024-08-09 14:20:59.789030 + +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +import sqlalchemy as sa +from alembic import op +from nonebot.log import logger + +if TYPE_CHECKING: + from collections.abc import Sequence + +revision: str = 'cfeab6961dce' +down_revision: str | Sequence[str] | None = 'f5b4a6d1325b' +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_tetriohistoricaldata', schema=None) as batch_op: + batch_op.alter_column( + 'api_type', existing_type=sa.VARCHAR(length=16), type_=sa.String(length=32), existing_nullable=False + ) + + # ### end Alembic commands ### + + +def downgrade(name: str = '') -> None: + if name: + return + # ### commands auto generated by Alembic - please adjust! ### + logger.warning('新数据可能不支持降级!') + logger.warning('请确认数据库内数据可以迁移到旧版本!') + input('如果确认可以迁移, 请按回车键继续!') + with op.batch_alter_table('nonebot_plugin_tetris_stats_tetriohistoricaldata', schema=None) as batch_op: + batch_op.alter_column( + 'api_type', existing_type=sa.String(length=32), type_=sa.VARCHAR(length=16), existing_nullable=False + ) + + # ### end Alembic commands ### diff --git a/nonebot_plugin_tetris_stats/games/tetrio/api/models.py b/nonebot_plugin_tetris_stats/games/tetrio/api/models.py index 9f8239b..0dc12ed 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/api/models.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/api/models.py @@ -13,6 +13,6 @@ from .typing import Summaries class TETRIOHistoricalData(MappedAsDataclass, Model): id: Mapped[int] = mapped_column(init=False, primary_key=True) user_unique_identifier: Mapped[str] = mapped_column(String(24), index=True) - api_type: Mapped[Literal['User Info', Summaries]] = mapped_column(String(16), index=True) + api_type: Mapped[Literal['User Info', Summaries]] = mapped_column(String(32), index=True) data: Mapped[SuccessModel] = mapped_column(PydanticType(get_model=[SuccessModel.__subclasses__], models=set())) update_time: Mapped[datetime] = mapped_column(DateTime, index=True)