apply_1_0_264.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """Apply UpdateScripts/1.0.264.sql to aidopdev."""
  2. from __future__ import annotations
  3. import pathlib
  4. import sys
  5. from _db import get_conn
  6. ROOT = pathlib.Path(__file__).resolve().parents[4]
  7. SQL = ROOT / "server" / "Admin.NET.Web.Entry" / "UpdateScripts" / "1.0.264.sql"
  8. def main() -> int:
  9. text = SQL.read_text(encoding="utf-8")
  10. parts = []
  11. buf = []
  12. for line in text.splitlines():
  13. if line.strip().startswith("--"):
  14. continue
  15. buf.append(line)
  16. if line.rstrip().endswith(";"):
  17. stmt = "\n".join(buf).strip().rstrip(";").strip()
  18. if stmt:
  19. parts.append(stmt)
  20. buf = []
  21. if buf:
  22. stmt = "\n".join(buf).strip().rstrip(";").strip()
  23. if stmt:
  24. parts.append(stmt)
  25. conn = get_conn()
  26. try:
  27. with conn.cursor() as cur:
  28. for i, stmt in enumerate(parts, 1):
  29. cur.execute(stmt)
  30. print(f"OK {i}/{len(parts)}")
  31. cur.execute(
  32. "SELECT entity_code FROM mdp_entity WHERE entity_code IN (%s,%s)",
  33. ("S6_REPORT", "S6_REPORT_API"),
  34. )
  35. print("entities", cur.fetchall())
  36. finally:
  37. conn.close()
  38. return 0
  39. if __name__ == "__main__":
  40. raise SystemExit(main())