| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- """
- 执行最终版模型表结构迁移脚本
- 运行方式:
- python scripts/run_create_final_model_tables.py
- 功能:
- - DROP 并重建 models_new、model_price_new、crawler_sync_log 表
- - ⚠️ 会清空上述三张表的所有数据,请确认目标数据库后再执行
- """
- import sys
- from pathlib import Path
- project_root = Path(__file__).parent.parent
- sys.path.insert(0, str(project_root))
- from app.database import engine
- from sqlalchemy import text
- MIGRATION_FILE = project_root / "migrations" / "create_final_model_tables.sql"
- def main():
- print("=" * 60)
- print("最终版模型表结构迁移")
- print("=" * 60)
- print(f"SQL 文件: {MIGRATION_FILE.name}")
- print()
- print("⚠️ 此操作将 DROP 并重建以下表:")
- print(" - aigcspace.models_new")
- print(" - aigcspace.model_price_new")
- print(" - aigcspace.crawler_sync_log")
- print()
- confirm = input("确认执行?(yes/no): ")
- if confirm.strip().lower() != "yes":
- print("已取消。")
- sys.exit(0)
- if not MIGRATION_FILE.exists():
- print(f"❌ 文件不存在: {MIGRATION_FILE}")
- sys.exit(1)
- sql = MIGRATION_FILE.read_text(encoding="utf-8")
- try:
- with engine.connect() as conn:
- conn.execute(text(sql))
- conn.commit()
- print("\n✅ 迁移执行成功")
- print(" 已创建:models_new / model_price_new / crawler_sync_log 及相关索引")
- except Exception as e:
- print(f"\n❌ 执行失败: {e}")
- sys.exit(1)
- if __name__ == "__main__":
- main()
|