feat: add database configuration and health check

This commit is contained in:
Schubert Ferenc 2026-07-01 20:50:17 +02:00
parent 3d53a94d59
commit 3701c50711
9 changed files with 72 additions and 2 deletions

5
backend/hermes/.env Normal file
View file

@ -0,0 +1,5 @@
DATABASE_URL=postgresql+psycopg://olympus:FsFs03285310!!!@olympus-db:5432/olympus
APP_NAME=Hermes API
APP_VERSION=0.1.0

View file

@ -0,0 +1,16 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
app_name: str = "Hermes API"
app_version: str = "0.1.0"
database_url: str
model_config = SettingsConfigDict(
env_file=".env",
case_sensitive=False
)
settings = Settings()

View file

@ -0,0 +1,29 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
engine = create_engine(
settings.database_url,
echo=False
)
SessionLocal = sessionmaker(
autocommit=False,
autoflush=False,
bind=engine
)
class Base(DeclarativeBase):
pass
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()

View file

@ -0,0 +1,12 @@
from sqlalchemy import text
from app.db.database import engine
def check_database() -> bool:
try:
with engine.connect() as connection:
connection.execute(text("SELECT 1"))
return True
except Exception:
return False

View file

@ -1,5 +1,7 @@
from fastapi import FastAPI
from app.db.health import check_database
app = FastAPI(
title="Hermes API",
version="0.1.0",
@ -9,9 +11,15 @@ app = FastAPI(
@app.get("/")
def root():
return {"service": "Hermes", "status": "running"}
return {
"service": "Hermes",
"status": "running"
}
@app.get("/health")
def health():
return {"status": "healthy"}
return {
"status": "healthy",
"database": check_database()
}