Skip to content

Commit 252b00d

Browse files
committed
feat(api): integrate real database operations into routes
- Implement actual database health check in /health endpoint - Return real schema information from /schema/{database_id} endpoint - Use SchemaIntrospector for live schema introspection - Report overall health status as 'degraded' when database unhealthy Closes acceptance criteria: Connection health checks pass
1 parent 18ea5ca commit 252b00d

1 file changed

Lines changed: 46 additions & 14 deletions

File tree

app/routes.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from app import __version__
1414
from app.logging_config import get_logger
15+
from db.connection import get_database
1516

1617
logger = get_logger(__name__)
1718

@@ -226,14 +227,30 @@ async def get_schema(database_id: str) -> SchemaResponse:
226227
"""
227228
logger.info("get_schema_request", database_id=database_id)
228229

229-
# TODO: Implement actual schema retrieval
230-
return SchemaResponse(
231-
database_id=database_id,
232-
dialect="postgresql",
233-
tables=[],
234-
table_count=0,
235-
last_updated=datetime.now(),
236-
)
230+
try:
231+
from db.schema import SchemaIntrospector
232+
233+
db_manager = await get_database()
234+
introspector = SchemaIntrospector(db_manager.engine)
235+
schema = await introspector.get_schema(database_id)
236+
237+
return SchemaResponse(
238+
database_id=schema.database_id,
239+
dialect=schema.dialect,
240+
tables=[table.to_dict() for table in schema.tables],
241+
table_count=len(schema.tables),
242+
last_updated=schema.last_updated,
243+
)
244+
except Exception as e:
245+
logger.error("get_schema_error", database_id=database_id, error=str(e))
246+
# Return empty schema on error for now
247+
return SchemaResponse(
248+
database_id=database_id,
249+
dialect="unknown",
250+
tables=[],
251+
table_count=0,
252+
last_updated=datetime.now(),
253+
)
237254

238255

239256
@router.post("/schema/register")
@@ -323,15 +340,30 @@ async def health_check() -> HealthResponse:
323340
324341
Returns health status of the API and its components.
325342
"""
343+
# Check database health
344+
db_status = "unhealthy"
345+
try:
346+
db_manager = await get_database()
347+
if await db_manager.health_check():
348+
db_status = "healthy"
349+
except Exception as e:
350+
logger.warning("health_check_database_error", error=str(e))
351+
db_status = "unhealthy"
352+
353+
# Determine overall status
354+
components = {
355+
"api": "healthy",
356+
"database": db_status,
357+
"model": "not_loaded", # TODO: Check model status in Phase 1.3
358+
}
359+
360+
overall_status = "healthy" if db_status == "healthy" else "degraded"
361+
326362
return HealthResponse(
327-
status="healthy",
363+
status=overall_status,
328364
version=__version__,
329365
timestamp=datetime.now(),
330-
components={
331-
"api": "healthy",
332-
"database": "healthy",
333-
"model": "healthy",
334-
},
366+
components=components,
335367
)
336368

337369

0 commit comments

Comments
 (0)