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

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