2024-05-25 16:11:52 +04:00
|
|
|
from fastapi import FastAPI
|
2024-05-25 16:51:34 +04:00
|
|
|
import logging
|
2024-05-25 16:11:52 +04:00
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
|
|
|
from database import create_tables, delete_tables
|
2024-06-02 17:33:50 +04:00
|
|
|
from router_questions import router as questions_router
|
|
|
|
from router_class import router as class_router
|
2024-05-25 16:11:52 +04:00
|
|
|
|
2024-05-25 16:51:34 +04:00
|
|
|
# Настройка логирования
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
logger = logging.getLogger(__name__)
|
2024-05-25 16:11:52 +04:00
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
async def lifespan(app: FastAPI):
|
|
|
|
await delete_tables()
|
2024-05-25 16:51:34 +04:00
|
|
|
logger.info("База данных очищена")
|
2024-05-25 16:11:52 +04:00
|
|
|
await create_tables()
|
2024-05-25 16:51:34 +04:00
|
|
|
logger.info("База данных готова к работе")
|
2024-05-25 16:11:52 +04:00
|
|
|
yield
|
2024-05-25 16:51:34 +04:00
|
|
|
logger.info("Выключение")
|
2024-05-25 16:11:52 +04:00
|
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan)
|
2024-05-25 16:51:34 +04:00
|
|
|
app.include_router(questions_router)
|
2024-06-02 17:33:50 +04:00
|
|
|
app.include_router(class_router)
|