fix(db): updated db setup for tests

This commit is contained in:
ribardej
2025-11-11 16:28:12 +01:00
parent 3cdefc33fc
commit 25e587cea8
4 changed files with 10 additions and 36 deletions

View File

@@ -3,20 +3,11 @@ from fastapi import Depends
from sqlalchemy.ext.asyncio import AsyncSession
from fastapi_users.db import SQLAlchemyUserDatabase
from ..core.db import async_session_maker, engine
from ..core.base import Base
from ..core.db import async_session_maker
from ..models.user import User, OAuthAccount
_initialized = False
async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
global _initialized
if not _initialized:
# Lazily ensure tables exist; helpful for test runs without migrations
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
_initialized = True
async with async_session_maker() as session:
yield session