File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 11import logging
2+ from fastapi .concurrency import asynccontextmanager
23from fastapi .responses import FileResponse
34from fastapi .staticfiles import StaticFiles
45import os
1112from apps .system .middleware .auth import TokenMiddleware
1213from common .core .config import settings
1314from common .core .response_middleware import ResponseMiddleware , exception_handler
15+ from alembic .config import Config
16+ from alembic import command
17+
18+ def run_migrations ():
19+ alembic_cfg = Config ("alembic.ini" )
20+ command .upgrade (alembic_cfg , "head" )
21+ @asynccontextmanager
22+ async def lifespan (app : FastAPI ):
23+ run_migrations ()
24+ yield
1425
1526def custom_generate_unique_id (route : APIRoute ) -> str :
1627 tag = route .tags [0 ] if route .tags and len (route .tags ) > 0 else ""
@@ -24,6 +35,7 @@ def custom_generate_unique_id(route: APIRoute) -> str:
2435 title = settings .PROJECT_NAME ,
2536 openapi_url = f"{ settings .API_V1_STR } /openapi.json" ,
2637 generate_unique_id_function = custom_generate_unique_id ,
38+ lifespan = lifespan
2739)
2840
2941# Set all CORS enabled origins
You can’t perform that action at this time.
0 commit comments