From 5cc33d5936f40c648def2a0e9140e78f33ddc074 Mon Sep 17 00:00:00 2001 From: MeetWq Date: Fri, 11 Oct 2024 23:52:02 +0800 Subject: [PATCH] enlarge message_id length (#58) --- .pre-commit-config.yaml | 4 +- .../0f0a7bc40f3c_message_id_length.py | 53 +++++++++++++++++++ nonebot_plugin_chatrecorder/model.py | 2 +- 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 nonebot_plugin_chatrecorder/migrations/0f0a7bc40f3c_message_id_length.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7b053a2..6999356 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] - stages: [Nonepre-commitNone] + stages: [commit] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-prettier @@ -18,4 +18,4 @@ repos: hooks: - id: prettier types_or: [javascript, jsx, ts, tsx, markdown, yaml, json] - stages: [Nonepre-commitNone] + stages: [commit] diff --git a/nonebot_plugin_chatrecorder/migrations/0f0a7bc40f3c_message_id_length.py b/nonebot_plugin_chatrecorder/migrations/0f0a7bc40f3c_message_id_length.py new file mode 100644 index 0000000..6cf9a6e --- /dev/null +++ b/nonebot_plugin_chatrecorder/migrations/0f0a7bc40f3c_message_id_length.py @@ -0,0 +1,53 @@ +"""message_id_length + +迁移 ID: 0f0a7bc40f3c +父迁移: 46327b837dd8 +创建时间: 2024-10-11 23:36:23.677012 + +""" + +from __future__ import annotations + +from collections.abc import Sequence + +import sqlalchemy as sa +from alembic import op + +revision: str = "0f0a7bc40f3c" +down_revision: str | Sequence[str] | None = "46327b837dd8" +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_chatrecorder_messagerecord", schema=None + ) as batch_op: + batch_op.alter_column( + "message_id", + existing_type=sa.String(length=64), + type_=sa.String(length=255), + existing_nullable=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_chatrecorder_messagerecord", schema=None + ) as batch_op: + batch_op.alter_column( + "message_id", + existing_type=sa.String(length=255), + type_=sa.String(length=64), + existing_nullable=False, + ) + + # ### end Alembic commands ### diff --git a/nonebot_plugin_chatrecorder/model.py b/nonebot_plugin_chatrecorder/model.py index 21b8619..cc7f7c8 100644 --- a/nonebot_plugin_chatrecorder/model.py +++ b/nonebot_plugin_chatrecorder/model.py @@ -19,7 +19,7 @@ class MessageRecord(Model): """ 消息时间\n\n存放 UTC 时间 """ type: Mapped[str] = mapped_column(String(32)) """ 消息类型\n\n此处主要包含 `message` 和 `message_sent` 两种\n\n`message_sent` 是 bot 发出的消息""" - message_id: Mapped[str] = mapped_column(String(64)) + message_id: Mapped[str] = mapped_column(String(255)) """ 消息id """ message: Mapped[JsonMsg] = mapped_column(JSON) """ 消息内容