mirror of
https://github.com/wowlikon/LibraryAPI.git
synced 2025-12-11 21:30:46 +00:00
Global refactoring of the project to use poetry and implement tests,
fixing bugs, changing the handling of dto and db models, preparing to add new functionality
This commit is contained in:
28
library_service/main.py
Normal file
28
library_service/main.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from toml import load
|
||||
|
||||
from .settings import engine, get_app
|
||||
from .routers import api_router
|
||||
from .routers.misc import get_info
|
||||
|
||||
app = get_app()
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
print("[+] Initializing...")
|
||||
|
||||
# Initialize the database
|
||||
with engine.begin() as connection:
|
||||
alembic_cfg.attributes['connection'] = connection
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
|
||||
print("[+] Starting...")
|
||||
yield # Here FastAPI will start handling requests;
|
||||
print("[+] Application shutdown")
|
||||
|
||||
# Include routers
|
||||
app.include_router(api_router)
|
||||
Reference in New Issue
Block a user