config di lifespan
This commit is contained in:
@@ -2,8 +2,13 @@ from collections.abc import AsyncGenerator
|
|||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||||
|
|
||||||
from api.app_builder.dependencies import init_dependencies
|
from api.app_builder.dependencies import init_dependencies
|
||||||
|
from api.infrastructure.dependencies.adapters import create_engine
|
||||||
|
from api.infrastructure.dependencies.configs import app_settings
|
||||||
|
from api.infrastructure.persistence.models import Base
|
||||||
|
from api.infrastructure.settings import Settings
|
||||||
|
|
||||||
from .routers import init_routers
|
from .routers import init_routers
|
||||||
|
|
||||||
@@ -11,6 +16,12 @@ from .routers import init_routers
|
|||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI) -> AsyncGenerator:
|
async def lifespan(app: FastAPI) -> AsyncGenerator:
|
||||||
print("init lifespan")
|
print("init lifespan")
|
||||||
|
app.dependency_overrides[Settings] = app_settings
|
||||||
|
app.dependency_overrides[AsyncEngine] = create_engine
|
||||||
|
engine = app.dependency_overrides[AsyncEngine](app.dependency_overrides[Settings]())
|
||||||
|
|
||||||
|
async with engine.begin() as conn:
|
||||||
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
7
api/infrastructure/persistence/models/__init__.py
Normal file
7
api/infrastructure/persistence/models/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from .base import Base
|
||||||
|
from .user import UserModel
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
"Base",
|
||||||
|
"UserModel",
|
||||||
|
)
|
Reference in New Issue
Block a user