_apply_remote_sql.py 855 B

12345678910111213141516171819202122232425262728
  1. import pymysql
  2. from pathlib import Path
  3. sql_path = Path(r"d:/Projects/Ai-DOP/SourceCode/ai-dop-platform/docs/db/V1__aidopcore_all_tables.sql")
  4. sql = sql_path.read_text(encoding='utf-8').replace('\n ,key ', '\n key ')
  5. conn = pymysql.connect(
  6. host='106.14.73.46',
  7. port=3306,
  8. user='aidopremote',
  9. password='AidOp#Remote2026$Secure',
  10. charset='utf8mb4',
  11. autocommit=True,
  12. )
  13. try:
  14. with conn.cursor() as cur:
  15. statements = [s.strip() for s in sql.split(';') if s.strip()]
  16. ok = 0
  17. for st in statements:
  18. cur.execute(st)
  19. ok += 1
  20. cur.execute("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='aidopcore'")
  21. table_count = cur.fetchone()[0]
  22. print(f"Applied statements: {ok}")
  23. print(f"aidopcore tables: {table_count}")
  24. finally:
  25. conn.close()