Fix deprecation warning by changing on_event to asynccontesxtmanager
This commit is contained in:
10
app/main.py
10
app/main.py
@@ -1,17 +1,21 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from contextlib import asynccontextmanager
|
||||
from .controllers import userManager, cardManager, groupManager, aaManager
|
||||
from .services.database import create_db_and_tables
|
||||
from .services.auth import token_router, create_first_user
|
||||
|
||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
||||
|
||||
app = FastAPI()
|
||||
@app.on_event("startup")
|
||||
def on_startup():
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
create_db_and_tables()
|
||||
create_first_user()
|
||||
print("Database created and tables initialized.")
|
||||
yield
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
|
||||
|
||||
app.include_router(token_router)
|
||||
|
||||
Reference in New Issue
Block a user