airlabs-manage/backend/reset_data.py
seaislee1209 11b1d9b105
All checks were successful
Build and Deploy Backend / build-and-deploy (push) Successful in 7m30s
Build and Deploy Web / build-and-deploy (push) Successful in 4m5s
chore: add reset_data.py for clearing demo data before production use
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 14:18:14 +08:00

40 lines
1.2 KiB
Python

"""清除所有业务数据,保留用户和角色
用途:正式启用前清除演示数据
"""
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✓ 所有业务数据已清除,用户和角色保留。系统已准备好正式使用。")