recreate_tables 改显式 confirm 参数, 移除 input() 阻塞

This commit is contained in:
HYC Fixer
2026-09-02 00:42:10 +08:00
parent e5c494f64b
commit f77a51247c
+9 -6
View File
@@ -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)