Fix: Added database initialization on startup to avoid 500 errors in production
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user