Files
momentry_core/tools/script/migration/migrate_all.py
T
Accusys ed95c447a9 feat: 三段式实体文件持久化设计文档和迁移工具
设计文档 (2458 行):
- 01_overview.md: 架构总览
- 02_file_profile_model.md: File Profile 数据模型
- 03_identity_profile_model.md: Identity Profile 数据模型
- 04_trace_profile_model.md: Trace Profile 数据模型
- 05_face_filter_model.md: Face Filter 统一模型
- 06_implementation_plan.md: 实施计划
- 07_progress_report.md: 进度报告

基础设施:
- 目录: config/global/, ~/momentry/identities/
- 迁移脚本:
  - generate_profiles.py (403 行)
  - generate_identities.py (210 行)
  - migrate_all.py (118 行)

测试验证:
- ✅ Dry-run 测试通过
- ✅ 找到 176 个文件
- ✅ 找到 117 个 Identity

关键改进:
- FaceFilterSettings 统一(前后端字段一致)
- 三段式架构(系统层/档案层/Identity层)
- 实体文件优先存储策略

状态: Phase 1 完成,Phase 2 开始
2026-10-09 13:26:36 +08:00

139 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""
迁移工具 - 一键执行所有迁移任务
执行顺序:
1. 生成 File Profile 文件
2. 生成 Identity Profile 文件
3. 更新 Trace Profile 文件
4. 生成索引文件
Usage:
python3 migrate_all.py [--dry-run]
"""
import argparse
import subprocess
import sys
from pathlib import Path
def run_script(script_path: str, args: list = None, dry_run: bool = False) -> bool:
"""运行迁移脚本"""
cmd = ["python3", script_path]
if args:
cmd.extend(args)
if dry_run:
cmd.append("--dry-run")
print(f"\n执行: {' '.join(cmd)}")
print("=" * 60)
try:
result = subprocess.run(cmd, check=True)
return result.returncode == 0
except subprocess.CalledProcessError as e:
print(f"❌ 脚本执行失败: {e}")
return False
except Exception as e:
print(f"❌ 意外错误: {e}")
return False
def main():
parser = argparse.ArgumentParser(description="一键执行所有迁移任务")
parser.add_argument(
"--dry-run",
action="store_true",
help="只打印将要执行的操作,不实际写入文件"
)
parser.add_argument(
"--output-dir",
default="/Users/accusys/momentry/output",
help="输出目录"
)
parser.add_argument(
"--identities-dir",
default="/Users/accusys/momentry/identities",
help="Identity 目录"
)
parser.add_argument(
"--database",
default="momentry",
help="数据库名称"
)
args = parser.parse_args()
print("=" * 60)
print("三段式实体文件持久化迁移工具")
print("=" * 60)
print()
print(f"输出目录: {args.output_dir}")
print(f"Identity 目录: {args.identities_dir}")
print(f"数据库: {args.database}")
print(f"Dry run: {args.dry_run}")
print()
# 脚本目录
script_dir = Path(__file__).parent
# 任务列表
tasks = [
{
"name": "生成 File Profile 文件",
"script": str(script_dir / "generate_profiles.py"),
"args": [
"--output-dir", args.output_dir,
"--database", args.database
]
},
{
"name": "生成 Identity Profile 文件",
"script": str(script_dir / "generate_identities.py"),
"args": [
"--identities-dir", args.identities_dir,
"--database", args.database
]
}
]
# 执行任务
success_count = 0
failed_count = 0
for task in tasks:
print()
print(f"任务: {task['name']}")
print("-" * 60)
if run_script(task["script"], task.get("args"), args.dry_run):
success_count += 1
else:
failed_count += 1
print(f"⚠️ 任务失败: {task['name']}")
response = input("继续下一个任务? (y/n): ")
if response.lower() != 'y':
print("迁移已中止")
break
# 总结
print()
print("=" * 60)
print("迁移完成")
print("=" * 60)
print(f"成功任务: {success_count}")
print(f"失败任务: {failed_count}")
if args.dry_run:
print()
print("这是 DRY-RUN 模式,没有实际写入文件")
print("移除 --dry-run 参数以实际执行")
if failed_count > 0:
sys.exit(1)
if __name__ == "__main__":
main()