#!/usr/bin/env python3 """ 清空 projects 与 operation_logs 表(保留 users)。 用法:cd backend && PYTHONPATH=src python3 scripts/clean_db.py """ import sys from pathlib import Path _backend = Path(__file__).resolve().parent.parent if str(_backend) not in sys.path: sys.path.insert(0, str(_backend)) from src.database import get_connection def main(): with get_connection() as conn: cur = conn.cursor() cur.execute("SET FOREIGN_KEY_CHECKS = 0") cur.execute("TRUNCATE TABLE operation_logs") cur.execute("TRUNCATE TABLE projects") cur.execute("SET FOREIGN_KEY_CHECKS = 1") cur.close() print("已清空 operation_logs、projects 表。") if __name__ == "__main__": main()