Automated Action 10ef945a25 Build simple Todo application with FastAPI and SQLite
- Created REST API for managing todo items
- Implemented SQLite database with SQLAlchemy ORM
- Added Alembic for database migrations
- Added health check endpoint

generated with BackendIM... (backend.im)
2025-05-13 06:22:39 +00:00

23 lines
548 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.db.database import get_db
router = APIRouter(
prefix="/health",
tags=["health"]
)
@router.get("/")
def health_check(db: Session = Depends(get_db)):
# Check if database connection is working by executing a simple query
try:
db.execute("SELECT 1")
db_status = "healthy"
except Exception:
db_status = "unhealthy"
return {
"status": "ok",
"database": db_status,
"api_version": "0.1.0"
}