"""Migration 2026-05-09c: source_health_checks und source_suggestions Schema. Diese DDL stand bislang inline in routers/sources.py (in /health/run, /health/run-stream, /health/search-fix). Phase 1 zieht sie hier raus, damit die Endpoints kein DDL mehr ausführen. Ausführung: DB_PATH=/home/claude-dev/osint-data/osint.db python3 migrations/2026-05-09c_source_health_schema.py DB_PATH=/home/claude-dev/AegisSight-Monitor-staging/data/osint.db python3 migrations/2026-05-09c_source_health_schema.py """ import os import sqlite3 import sys def main(db_path: str) -> int: if not os.path.exists(db_path): print(f"FEHLER: DB nicht gefunden: {db_path}", file=sys.stderr) return 1 conn = sqlite3.connect(db_path, timeout=60) conn.execute("PRAGMA busy_timeout = 60000") conn.execute("PRAGMA journal_mode = WAL") print(f"Migration auf {db_path}") conn.executescript(""" CREATE TABLE IF NOT EXISTS source_health_checks ( id INTEGER PRIMARY KEY AUTOINCREMENT, source_id INTEGER NOT NULL REFERENCES sources(id) ON DELETE CASCADE, check_type TEXT NOT NULL, status TEXT NOT NULL, message TEXT, details TEXT, checked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_source_health_checks_source ON source_health_checks(source_id); CREATE INDEX IF NOT EXISTS idx_source_health_checks_status ON source_health_checks(status); CREATE TABLE IF NOT EXISTS source_suggestions ( id INTEGER PRIMARY KEY AUTOINCREMENT, suggestion_type TEXT NOT NULL, title TEXT NOT NULL, description TEXT, source_id INTEGER REFERENCES sources(id) ON DELETE SET NULL, suggested_data TEXT, priority TEXT DEFAULT 'medium', status TEXT DEFAULT 'pending', reviewed_at TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_source_suggestions_status ON source_suggestions(status); CREATE INDEX IF NOT EXISTS idx_source_suggestions_source ON source_suggestions(source_id); """) print(" + source_health_checks + Indizes (idempotent)") print(" + source_suggestions + Indizes (idempotent)") conn.commit() conn.close() print("Migration abgeschlossen.") return 0 if __name__ == "__main__": db_path = os.environ.get("DB_PATH", "/home/claude-dev/osint-data/osint.db") sys.exit(main(db_path))