Fix database health check by adding commit after query execution
This commit is contained in:
parent
6705b7a5e2
commit
652f32404a
@ -1,5 +1,6 @@
|
|||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
from sqlalchemy import text
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from app.db.session import get_db
|
from app.db.session import get_db
|
||||||
@ -13,11 +14,12 @@ def health_check(db: Session = Depends(get_db)):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Check database connection
|
# Check database connection
|
||||||
db.execute("SELECT 1")
|
db.execute(text("SELECT 1"))
|
||||||
|
db.commit()
|
||||||
db_status = "healthy"
|
db_status = "healthy"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db_status = f"unhealthy: {str(e)}"
|
db_status = f"unhealthy: {str(e)}"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"status": "healthy",
|
"status": "healthy",
|
||||||
"timestamp": datetime.utcnow(),
|
"timestamp": datetime.utcnow(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user