Automated Action 852e0a32b1 Create simple FastAPI application with SQLite and Alembic
- Set up project structure
- Create FastAPI app with health endpoint
- Implement SQLAlchemy with SQLite database
- Set up Alembic for database migrations
- Create CRUD operations for items
- Add comprehensive documentation
2025-05-20 14:20:21 +00:00

25 lines
656 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.db.session import get_db
router = APIRouter()
@router.get("/health", summary="Health check endpoint")
def health_check(db: Session = Depends(get_db)):
"""
Health check endpoint to verify that the API is running and can connect to the database.
Returns:
dict: A JSON object with the status of the service and database connection
"""
db_status = "healthy"
try:
# Try to execute a simple query
db.execute("SELECT 1")
except Exception:
db_status = "unhealthy"
return {"status": "ok", "database": db_status}