30 lines
743 B
Python
30 lines
743 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy import text
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.config import settings
|
|
from app.db.session import get_db
|
|
|
|
|
|
router = APIRouter(prefix="/api", tags=["health"])
|
|
|
|
|
|
@router.get("/health")
|
|
def healthcheck() -> dict[str, str]:
|
|
return {
|
|
"status": "ok",
|
|
"environment": settings.app_env,
|
|
"app_name": settings.app_name,
|
|
}
|
|
|
|
|
|
@router.get("/db-health")
|
|
def database_healthcheck(db: Session = Depends(get_db)) -> dict[str, str | int]:
|
|
result = db.execute(text("SELECT 1")).scalar_one()
|
|
return {
|
|
"status": "ok",
|
|
"database": "connected",
|
|
"result": result,
|
|
"sqlite_file": settings.sqlite_file_path or "not-applicable",
|
|
}
|