import os from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker from sqlalchemy.orm import declarative_base DATABASE_URL = os.getenv("DATABASE_URL", "postgresql+asyncpg://postgres:postgres@localhost:5432/pulseguard") if "sqlite" in DATABASE_URL: engine = create_async_engine( DATABASE_URL, echo=False, future=True ) else: engine = create_async_engine( DATABASE_URL, echo=False, future=True, pool_size=10, max_overflow=20 ) async_session = async_sessionmaker( engine, class_=AsyncSession, expire_on_commit=False ) Base = declarative_base() async def init_db(): async with engine.begin() as conn: # Import models inside to avoid circular reference from models import AuditLog, ReliabilityEvent, BenchmarkResult await conn.run_sync(Base.metadata.create_all)