Fixed the database connection error that was causing degraded system health by using the proper DatabaseManager API instead of non-existent methods. ## Root Cause Analysis: - **Issue**: `_show_core_system_stats()` tried to call `db_manager.get_connection()` - **Problem**: DatabaseManager class doesn't have a `get_connection()` method - **Impact**: System health reported as "Degraded (66.7%)" due to database unavailability ## Why No Tests Caught This: 1. **Existing tests** only test public API methods (`store_markdown_file`, `get_markdown_file`, etc.) 2. **No tests existed** for `get_connection()` because the method doesn't exist 3. **New stats function** was the first code to assume this method existed 4. **Database pattern**: Uses temporary connections per operation, not persistent connections ## Solution Applied: - **Replaced** `conn = db_manager.get_connection()` with proper `execute_query()` API - **Updated queries** to use named columns: `SELECT COUNT(*) as count FROM table` - **Added resilience** for optional tables (schema_files) with try/catch - **Result**: System health now reports ✅ **100% Healthy** ## Changes Made: ```python # Before (broken): conn = db_manager.get_connection() cursor.execute("SELECT COUNT(*) FROM markdown_files") total_files = cursor.fetchone()[0] # After (correct): result = db_manager.execute_query("SELECT COUNT(*) as count FROM markdown_files") total_files = result[0]['count'] if result else 0 ``` ## Current System Health: ``` 🏥 System Health: ✅ Healthy (100.0%) Healthy Subsystems: 3/3 🗄️ Database: ✅ Available (56.0 KB) - 11 files processed 🗃️ Cache: ✅ Available (0 B) 🖥️ AST Service: ✅ Available ``` This fix demonstrates the value of the health monitoring system - it successfully identified a real integration issue and provided clear diagnostic information. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
126 KiB
126 KiB