
- Set up project structure and requirements - Create database models and connection setup using SQLAlchemy - Set up Alembic migrations - Create API endpoints for Todo CRUD operations - Add health endpoint - Update README with project information generated with BackendIM... (backend.im)
22 lines
577 B
Python
22 lines
577 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy import text
|
|
|
|
from app.database.database import get_db
|
|
|
|
router = APIRouter(tags=["health"])
|
|
|
|
@router.get("/health")
|
|
def health_check(db: Session = Depends(get_db)):
|
|
# Try to execute a simple query to check database connection
|
|
try:
|
|
db.execute(text("SELECT 1"))
|
|
db_status = "healthy"
|
|
except Exception as e:
|
|
db_status = f"unhealthy: {str(e)}"
|
|
|
|
return {
|
|
"status": "ok",
|
|
"database_status": db_status,
|
|
"version": "1.0.0"
|
|
} |