Fix: Added database initialization on startup to avoid 500 errors in production

This commit is contained in:
2026-02-22 10:23:15 -05:00
parent 1f59f87614
commit d50020ade2
3 changed files with 95 additions and 80 deletions

View File

@ -5,6 +5,7 @@ from fastapi.staticfiles import StaticFiles
import os
from app.core.config import settings
from app.core.database import init_db
from app.api.routes import router as routes_router
from app.api.bus_stops import router as bus_stops_router
from app.api.schedules import router as schedules_router
@ -19,11 +20,20 @@ from app.api.analytics import router as analytics_router
from app.api.reports import router as reports_router
from app.api.shuttles import router as shuttles_router
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
# Initialize database
init_db()
yield
app = FastAPI(
title="SIBU Transportation API",
description="API for SIBU public transportation system",
version="1.0.0",
debug=settings.debug,
lifespan=lifespan
)
# CORS middleware