From f77a51247c8e4ecfe089415883f758a03aa8bf01 Mon Sep 17 00:00:00 2001 From: HYC Fixer Date: Wed, 2 Sep 2026 00:42:10 +0800 Subject: [PATCH] =?UTF-8?q?recreate=5Ftables=20=E6=94=B9=E6=98=BE=E5=BC=8F?= =?UTF-8?q?=20confirm=20=E5=8F=82=E6=95=B0,=20=E7=A7=BB=E9=99=A4=20input()?= =?UTF-8?q?=20=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/database.py b/core/database.py index 232030b..732b9bf 100644 --- a/core/database.py +++ b/core/database.py @@ -1538,14 +1538,17 @@ class DatabaseManager: session.execute(text("VACUUM")) session.commit() - def recreate_tables(self): - """重建所有表(危险操作!会清空数据)""" - print("警告: 即将重建所有数据库表,这将删除所有数据!") - confirm = input("输入 'yes' 确认: ") - if confirm != 'yes': - print("操作已取消") + def recreate_tables(self, confirm: bool = False): + """重建所有表(危险操作!会清空数据) + + 由调用方显式传 confirm=True;不再使用 input() 阻塞, + 避免在服务器进程内挂起工作线程。 + """ + if not confirm: + print("操作已取消(recreate_tables 需要 confirm=True)") return + print("警告: 即将重建所有数据库表,这将删除所有数据!") with self.session() as session: # 删除所有表 Base.metadata.drop_all(self.engine)