Răsfoiți Sursa

Add DB path validation to backfill script

Lukas Goldschmidt 1 săptămână în urmă
părinte
comite
27b8201213
1 a modificat fișierele cu 16 adăugiri și 0 ștergeri
  1. 16 0
      scripts/normalize_cluster_timestamps.py

+ 16 - 0
scripts/normalize_cluster_timestamps.py

@@ -97,6 +97,22 @@ def main() -> None:
     args = parser.parse_args()
 
     db_path = str(args.db)
+    if not Path(db_path).exists():
+        print(f"ERROR: database file not found: {db_path}")
+        print("Check NEWS_MCP_DB_PATH env var or pass --db /path/to/db")
+        sys.exit(1)
+
+    # Quick check: does the clusters table exist?
+    with sqlite3.connect(db_path) as probe:
+        tables = {row[0] for row in probe.execute(
+            "SELECT name FROM sqlite_master WHERE type='table'"
+        ).fetchall()}
+        if "clusters" not in tables:
+            print(f"ERROR: 'clusters' table not found in {db_path}")
+            print(f"  Tables present: {sorted(tables) or '(none)'}")
+            print("  This may not be the correct database file.")
+            sys.exit(1)
+
     print(f"Database: {db_path}")
     print(f"Dry run:  {args.dry_run}")