diff --git a/apps/api/src/main.py b/apps/api/src/main.py index 043f656..1ebb411 100644 --- a/apps/api/src/main.py +++ b/apps/api/src/main.py @@ -123,8 +123,9 @@ async def on_startup(): # Initialize database (run migrations) db_ready = await init_database() if not db_ready: - logger.error("Database initialization failed. API may not function correctly.") - # Continue anyway so the health endpoint remains available + logger.error("Database initialization failed. Shutting down.") + import sys + sys.exit(1) # Seed built-in data await seed_builtin_tool_types() @@ -132,7 +133,14 @@ async def on_startup(): @app.get("/health") async def health_check(): - return {"status": "healthy"} + try: + from sqlalchemy import text + async with SessionLocal() as session: + await session.execute(text("SELECT 1")) + return {"status": "healthy", "database": "connected"} + except Exception as exc: + logger.error("Health check failed: %s", exc) + return {"status": "unhealthy", "database": "disconnected", "error": str(exc)} app.include_router(auth_router) app.include_router(projects_router)