PIbd-32_Kashin_M.I_API_Cour.../main.py

23 lines
660 B
Python

from fastapi import FastAPI
import logging
from contextlib import asynccontextmanager
from database import create_tables, delete_tables
from router import router as questions_router
# Настройка логирования
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
await delete_tables()
logger.info("База данных очищена")
await create_tables()
logger.info("База данных готова к работе")
yield
logger.info("Выключение")
app = FastAPI(lifespan=lifespan)
app.include_router(questions_router)