from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession from sqlalchemy.orm import DeclarativeBase from app.config import settings engine = create_async_engine(settings.database_url, echo=False) AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False) class Base(DeclarativeBase): pass async def init_db() -> None: # Import models so their tables are registered on Base.metadata before create_all from app.models import user, entry # noqa: F401 async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all)