52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
|
|
#!/usr/bin/env python
|
|||
|
|
"""迁移启动脚本 - 用于执行数据库迁移
|
|||
|
|
|
|||
|
|
使用方法:
|
|||
|
|
python run_migration.py
|
|||
|
|
"""
|
|||
|
|
import sys
|
|||
|
|
import os
|
|||
|
|
|
|||
|
|
# 添加项目根目录到Python路径
|
|||
|
|
project_root = os.path.abspath(os.path.dirname(__file__))
|
|||
|
|
sys.path.insert(0, project_root)
|
|||
|
|
|
|||
|
|
# 重要:先加载.env文件,再导入模块
|
|||
|
|
from lawrisk.utils.env_loader import load_env
|
|||
|
|
load_env('.env', override=False)
|
|||
|
|
|
|||
|
|
# 导入并执行迁移
|
|||
|
|
from lawrisk.utils.migrate_unit_permission import execute_migration, check_migration_status
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
print("=" * 60)
|
|||
|
|
print("许可管理单位权限优化 - 数据库迁移")
|
|||
|
|
print("=" * 60)
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
# 检查当前状态
|
|||
|
|
status = check_migration_status()
|
|||
|
|
print(f"迁移状态: {'已完成' if status['migration_complete'] else '未完成'}")
|
|||
|
|
print()
|
|||
|
|
|
|||
|
|
if not status['migration_complete']:
|
|||
|
|
response = input("是否执行数据库迁移?(y/N): ").strip().lower()
|
|||
|
|
if response == 'y':
|
|||
|
|
print("\n开始执行迁移...")
|
|||
|
|
results = execute_migration()
|
|||
|
|
|
|||
|
|
if results['success']:
|
|||
|
|
print("\n✅ 迁移成功完成!")
|
|||
|
|
print(" - 架构迁移: ✅")
|
|||
|
|
print(" - 数据迁移: ✅")
|
|||
|
|
else:
|
|||
|
|
print("\n❌ 迁移失败!")
|
|||
|
|
for error in results['errors']:
|
|||
|
|
print(f" 错误: {error}")
|
|||
|
|
else:
|
|||
|
|
print("\n跳过迁移")
|
|||
|
|
else:
|
|||
|
|
print("数据库已完全迁移,无需重复执行")
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 60)
|