|
12 | 12 |
|
13 | 13 | from app import __version__ |
14 | 14 | from app.logging_config import get_logger |
| 15 | +from db.connection import get_database |
15 | 16 |
|
16 | 17 | logger = get_logger(__name__) |
17 | 18 |
|
@@ -226,14 +227,30 @@ async def get_schema(database_id: str) -> SchemaResponse: |
226 | 227 | """ |
227 | 228 | logger.info("get_schema_request", database_id=database_id) |
228 | 229 |
|
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 | + ) |
237 | 254 |
|
238 | 255 |
|
239 | 256 | @router.post("/schema/register") |
@@ -323,15 +340,30 @@ async def health_check() -> HealthResponse: |
323 | 340 |
|
324 | 341 | Returns health status of the API and its components. |
325 | 342 | """ |
| 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 | + |
326 | 362 | return HealthResponse( |
327 | | - status="healthy", |
| 363 | + status=overall_status, |
328 | 364 | version=__version__, |
329 | 365 | timestamp=datetime.now(), |
330 | | - components={ |
331 | | - "api": "healthy", |
332 | | - "database": "healthy", |
333 | | - "model": "healthy", |
334 | | - }, |
| 366 | + components=components, |
335 | 367 | ) |
336 | 368 |
|
337 | 369 |
|
|
0 commit comments