24 lines
615 B
Python
24 lines
615 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.database import get_db
|
|
|
|
router = APIRouter(
|
|
tags=["health"],
|
|
)
|
|
|
|
@router.get("/health")
|
|
def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint to verify API and database connectivity
|
|
"""
|
|
# Try to execute a simple SQL query to verify database connection
|
|
try:
|
|
db.execute("SELECT 1")
|
|
db_status = "healthy"
|
|
except Exception:
|
|
db_status = "unhealthy"
|
|
|
|
return {
|
|
"status": "ok" if db_status == "healthy" else "error",
|
|
"database": db_status
|
|
} |