2025-06-01 10:05:16 +00:00

32 lines
839 B
Python

from typing import Any, Dict
from fastapi import APIRouter, Depends
from sqlalchemy import text
from sqlalchemy.orm import Session
from app.db.utils import get_db
router = APIRouter()
@router.get("/", response_model=Dict[str, Any])
async def health_check(db: Session = Depends(get_db)) -> Any:
"""
Health check endpoint to verify the API and database are running.
"""
health_status = {
"status": "healthy",
"api": "ok",
"database": "ok",
}
# Check database connection
try:
# Execute a simple query to check if the database is responsive
db.execute(text("SELECT 1"))
except Exception as e:
health_status["status"] = "unhealthy"
health_status["database"] = "error"
health_status["database_error"] = str(e)
return health_status