chore: add reset_data.py for clearing demo data before production use
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a43bed1d64
commit
11b1d9b105
39
backend/reset_data.py
Normal file
39
backend/reset_data.py
Normal file
@ -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✓ 所有业务数据已清除,用户和角色保留。系统已准备好正式使用。")
|
||||
Loading…
x
Reference in New Issue
Block a user