initial skeleton: FastAPI + SQLAlchemy + schema rendicontazione + template RE-START
This commit is contained in:
24
app/routers/health.py
Normal file
24
app/routers/health.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import text
|
||||
from ..db import get_db
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/health")
|
||||
def health(db: Session = Depends(get_db)):
|
||||
# Verifica connessione DB e schema
|
||||
try:
|
||||
result = db.execute(text("SELECT current_schema(), current_user, now();")).first()
|
||||
return {
|
||||
"status": "ok",
|
||||
"service": "rendicontazione-api",
|
||||
"db": {
|
||||
"schema": result[0],
|
||||
"user": result[1],
|
||||
"now": str(result[2]),
|
||||
},
|
||||
}
|
||||
except Exception as e:
|
||||
return {"status": "degraded", "error": str(e)}
|
||||
Reference in New Issue
Block a user