recreate_tables 改显式 confirm 参数, 移除 input() 阻塞
This commit is contained in:
+9
-6
@@ -1538,14 +1538,17 @@ class DatabaseManager:
|
|||||||
session.execute(text("VACUUM"))
|
session.execute(text("VACUUM"))
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
def recreate_tables(self):
|
def recreate_tables(self, confirm: bool = False):
|
||||||
"""重建所有表(危险操作!会清空数据)"""
|
"""重建所有表(危险操作!会清空数据)
|
||||||
print("警告: 即将重建所有数据库表,这将删除所有数据!")
|
|
||||||
confirm = input("输入 'yes' 确认: ")
|
由调用方显式传 confirm=True;不再使用 input() 阻塞,
|
||||||
if confirm != 'yes':
|
避免在服务器进程内挂起工作线程。
|
||||||
print("操作已取消")
|
"""
|
||||||
|
if not confirm:
|
||||||
|
print("操作已取消(recreate_tables 需要 confirm=True)")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
print("警告: 即将重建所有数据库表,这将删除所有数据!")
|
||||||
with self.session() as session:
|
with self.session() as session:
|
||||||
# 删除所有表
|
# 删除所有表
|
||||||
Base.metadata.drop_all(self.engine)
|
Base.metadata.drop_all(self.engine)
|
||||||
|
|||||||
Reference in New Issue
Block a user