From 876cfb421a59432c073447e8c29705b8b8523c1a Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Sun, 19 Feb 2023 12:29:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8C=5Frun=5Fscript=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0try?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/word_bank/_model.py | 2 +- services/db_context.py | 9 ++++++--- services/log.py | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/word_bank/_model.py b/plugins/word_bank/_model.py index d32ca750..1e815a9c 100644 --- a/plugins/word_bank/_model.py +++ b/plugins/word_bank/_model.py @@ -500,4 +500,4 @@ class WordBank(Model): @classmethod async def _run_script(cls): await cls.raw("ALTER TABLE word_bank2 ADD to_me varchar(255);") - """允许 user_join_time 为空""" + """添加 to_me 字段""" diff --git a/services/db_context.py b/services/db_context.py index 8af0cc4f..5c855bba 100755 --- a/services/db_context.py +++ b/services/db_context.py @@ -27,7 +27,7 @@ class Model(Model_): MODELS.append(cls.__module__) if func := getattr(cls, "_run_script", None): - SCRIPT_METHOD.append(func) + SCRIPT_METHOD.append((cls.__module__, func)) class TestSQL(Model): @@ -53,8 +53,11 @@ async def init(): except Exception as e: raise Exception(f"数据库连接错误.... {type(e)}: {e}") if SCRIPT_METHOD: - for func in SCRIPT_METHOD: - await func() + for module, func in SCRIPT_METHOD: + try: + await func() + except Exception as e: + logger.debug(f"{module} 执行SQL", e=e) async def disconnect(): diff --git a/services/log.py b/services/log.py index 7d52bbd5..e1898e82 100755 --- a/services/log.py +++ b/services/log.py @@ -109,6 +109,7 @@ class logger: user_id: Optional[int] = None, group_id: Optional[int] = None, target: Optional[Any] = None, + e: Optional[Exception] = None, ): template = cls.__parser_template(info, command, user_id, group_id, target) logger_.opt(colors=True).debug(template)