Skip to content

Commit

Permalink
add migration warning
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetWq committed Aug 8, 2023
1 parent 5199119 commit 376e8a1
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import sqlalchemy as sa
from alembic import op
from nonebot.log import logger
from sqlalchemy import insert, select, update
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
Expand All @@ -25,6 +26,8 @@ def upgrade() -> None:
MessageRecord = Base.classes.nonebot_plugin_chatrecorder_messagerecord
SessionModel = Base.classes.nonebot_plugin_session_sessionmodel
with Session(op.get_bind()) as session:
logger.warning("正在迁移聊天记录数据,请不要关闭程序...")

statement = select(MessageRecord)
messages = session.scalars(statement).all()

Expand Down Expand Up @@ -105,6 +108,7 @@ def upgrade() -> None:
)
if bulk_update_messages:
session.execute(update(MessageRecord), bulk_update_messages)
logger.warning("聊天记录数据迁移完成!")

with op.batch_alter_table(
"nonebot_plugin_chatrecorder_messagerecord", schema=None
Expand Down

0 comments on commit 376e8a1

Please sign in to comment.