From 11b1d9b10521d74b15f9e3ddb9be2a81fea051e8 Mon Sep 17 00:00:00 2001 From: seaislee1209 Date: Wed, 25 Feb 2026 14:18:14 +0800 Subject: [PATCH] chore: add reset_data.py for clearing demo data before production use Co-Authored-By: Claude Opus 4.6 --- backend/reset_data.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/reset_data.py diff --git a/backend/reset_data.py b/backend/reset_data.py new file mode 100644 index 0000000..1ce98a9 --- /dev/null +++ b/backend/reset_data.py @@ -0,0 +1,39 @@ +"""清除所有业务数据,保留用户和角色 +用途:正式启用前清除演示数据 +""" +from database import SessionLocal +from models import ( + SubmissionHistory, Submission, OutsourceCost, CostOverride, + AIToolCostAllocation, AIToolCost, OverheadCost, ProjectMilestone, Project +) + +db = SessionLocal() + +tables = [ + ("提交历史", SubmissionHistory), + ("内容提交", Submission), + ("外包成本", OutsourceCost), + ("人力调整", CostOverride), + ("AI工具分摊", AIToolCostAllocation), + ("AI工具成本", AIToolCost), + ("固定开支", OverheadCost), + ("项目里程碑", ProjectMilestone), + ("项目", Project), +] + +print("即将清除以下数据(用户和角色不受影响):") +for label, model in tables: + count = db.query(model).count() + print(f" {label}: {count} 条") + +confirm = input("\n确认清除?输入 yes 继续: ") +if confirm.strip().lower() != "yes": + print("已取消") + exit() + +for label, model in tables: + deleted = db.query(model).delete() + print(f" 已删除 {label}: {deleted} 条") + +db.commit() +print("\n✓ 所有业务数据已清除,用户和角色保留。系统已准备好正式使用。")