feat: add backup monitoring database schema
This commit is contained in:
@@ -186,6 +186,50 @@ class SettingsStore:
|
|||||||
conn.execute(
|
conn.execute(
|
||||||
"CREATE INDEX IF NOT EXISTS idx_monitoring_machine_actions_action_status ON monitoring_machine_actions(action, status)"
|
"CREATE INDEX IF NOT EXISTS idx_monitoring_machine_actions_action_status ON monitoring_machine_actions(action, status)"
|
||||||
)
|
)
|
||||||
|
conn.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS backup_jobs (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
name TEXT NOT NULL UNIQUE,
|
||||||
|
source TEXT,
|
||||||
|
target TEXT,
|
||||||
|
schedule_interval_seconds INTEGER,
|
||||||
|
created_at INTEGER NOT NULL
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
conn.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS backup_runs (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
job_id TEXT NOT NULL,
|
||||||
|
started_at INTEGER NOT NULL,
|
||||||
|
ended_at INTEGER,
|
||||||
|
status TEXT NOT NULL,
|
||||||
|
bytes_transferred INTEGER,
|
||||||
|
duration_ms INTEGER,
|
||||||
|
error_message TEXT,
|
||||||
|
details_json TEXT,
|
||||||
|
created_at INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (job_id) REFERENCES backup_jobs(id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
conn.execute("CREATE INDEX IF NOT EXISTS idx_backup_runs_job_id ON backup_runs(job_id)")
|
||||||
|
conn.execute("CREATE INDEX IF NOT EXISTS idx_backup_runs_status ON backup_runs(status)")
|
||||||
|
conn.execute("""
|
||||||
|
CREATE TABLE IF NOT EXISTS backup_alerts (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
job_id TEXT NOT NULL,
|
||||||
|
run_id TEXT,
|
||||||
|
alert_type TEXT NOT NULL,
|
||||||
|
severity TEXT NOT NULL,
|
||||||
|
message TEXT NOT NULL,
|
||||||
|
acknowledged INTEGER NOT NULL DEFAULT 0,
|
||||||
|
resolved_at INTEGER,
|
||||||
|
created_at INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (job_id) REFERENCES backup_jobs(id),
|
||||||
|
FOREIGN KEY (run_id) REFERENCES backup_runs(id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
conn.execute("CREATE INDEX IF NOT EXISTS idx_backup_alerts_job_id ON backup_alerts(job_id)")
|
||||||
|
conn.execute("CREATE INDEX IF NOT EXISTS idx_backup_alerts_acknowledged ON backup_alerts(acknowledged)")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _normalize_services(value: Any, fallback: list[str] | None = None) -> list[str]:
|
def _normalize_services(value: Any, fallback: list[str] | None = None) -> list[str]:
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
from media_library_viewer_api.services.settings_store import SettingsStore
|
||||||
|
|
||||||
|
|
||||||
|
def test_backup_schema_created():
|
||||||
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
db_path = Path(tmpdir) / "test_settings.sqlite"
|
||||||
|
store = SettingsStore(db_path)
|
||||||
|
store.init_schema()
|
||||||
|
with store.connect() as conn:
|
||||||
|
tables = conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'backup_%'").fetchall()
|
||||||
|
table_names = [t[0] for t in tables]
|
||||||
|
assert "backup_jobs" in table_names
|
||||||
|
assert "backup_runs" in table_names
|
||||||
|
assert "backup_alerts" in table_names
|
||||||
Reference in New Issue
Block a user