import logging from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession from sqlalchemy.orm import sessionmaker, declarative_base # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) DATABASE_URL = "sqlite+aiosqlite:///./auth.db" engine = create_async_engine( DATABASE_URL, echo=False, future=True ) AsyncSessionLocal = sessionmaker( engine, class_=AsyncSession, expire_on_commit=False ) Base = declarative_base() async def init_db(): from .models import Base logger.info("Initializing SQLite database at data/auth.db") try: async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) logger.info("Database initialized successfully") except Exception as e: logger.error(f"Failed to initialize database: {str(e)}") raise async def get_db(): async with AsyncSessionLocal() as session: yield session