From eed472a33bce5e1c7c94a374c5db9cfcb2a5a545 Mon Sep 17 00:00:00 2001 From: aditisinghal tech Date: Tue, 2 Jun 2026 22:20:28 +0530 Subject: [PATCH] feat: add database health check endpoint --- backend/app.py | 11 ++++++++++- backend/tests/test_api.py | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/app.py b/backend/app.py index f7109ed..42bef4f 100644 --- a/backend/app.py +++ b/backend/app.py @@ -21,7 +21,7 @@ from routes.plugins import router as plugins_router from routes.export import router as export_router from routes.settings import router as settings_router -from services.db_service import init_db +from services.db_service import init_db, get_db logging.basicConfig( level=logging.INFO, @@ -90,3 +90,12 @@ async def root(): @app.get("/health", tags=["Health"]) async def health(): return {"status": "healthy"} + +@app.get("/health/db", tags=["Health"]) +async def db_health(): + try: + with get_db() as conn: + conn.execute("SELECT 1") + return {"status": "healthy"} + except Exception: + return {"status": "unhealthy"} \ No newline at end of file diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index e38105e..e9717a3 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -29,6 +29,11 @@ def test_health(): assert r.json()["status"] == "healthy" +def test_db_health(): + r = client.get("/health/db") + assert r.status_code == 200 + assert r.json()["status"] == "healthy" + # ─── Sessions ──────────────────────────────────────────── def test_create_session(): r = client.post("/api/sessions/", json={"title": "Test Chat", "model": "llama3"})