mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
debug: add connection-level diagnostics to trace database access
Enhanced diagnostics to trace database path resolution and table existence at connection time. This will help identify if get_db_connection() is resolving paths correctly and accessing the right database file. Added diagnostics to: - get_db_connection(): Show input path, resolved path, file existence, and tables found - initialize_dev_database(): Verify tables exist after creation This will reveal whether the path resolution is working correctly or if there's a timing/caching issue with database file access.
This commit is contained in:
@@ -32,15 +32,26 @@ def get_db_connection(db_path: str = "data/jobs.db") -> sqlite3.Connection:
|
|||||||
"""
|
"""
|
||||||
# Resolve path based on deployment mode
|
# Resolve path based on deployment mode
|
||||||
resolved_path = get_db_path(db_path)
|
resolved_path = get_db_path(db_path)
|
||||||
|
print(f"🔍 DIAGNOSTIC [get_db_connection]: Input path='{db_path}', Resolved path='{resolved_path}'")
|
||||||
|
|
||||||
# Ensure data directory exists
|
# Ensure data directory exists
|
||||||
db_path_obj = Path(resolved_path)
|
db_path_obj = Path(resolved_path)
|
||||||
db_path_obj.parent.mkdir(parents=True, exist_ok=True)
|
db_path_obj.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
# Check if database file exists
|
||||||
|
file_exists = db_path_obj.exists()
|
||||||
|
print(f"🔍 DIAGNOSTIC [get_db_connection]: Database file exists: {file_exists}")
|
||||||
|
|
||||||
conn = sqlite3.connect(resolved_path, check_same_thread=False)
|
conn = sqlite3.connect(resolved_path, check_same_thread=False)
|
||||||
conn.execute("PRAGMA foreign_keys = ON")
|
conn.execute("PRAGMA foreign_keys = ON")
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
|
|
||||||
|
# Verify tables exist
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
||||||
|
tables = [row[0] for row in cursor.fetchall()]
|
||||||
|
print(f"🔍 DIAGNOSTIC [get_db_connection]: Tables in database: {tables}")
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
|
||||||
@@ -274,6 +285,15 @@ def initialize_dev_database(db_path: str = "data/trading_dev.db") -> None:
|
|||||||
initialize_database(db_path)
|
initialize_database(db_path)
|
||||||
print(f"🔍 DIAGNOSTIC: initialize_dev_database() COMPLETED successfully")
|
print(f"🔍 DIAGNOSTIC: initialize_dev_database() COMPLETED successfully")
|
||||||
|
|
||||||
|
# Verify tables were created
|
||||||
|
print(f"🔍 DIAGNOSTIC: Verifying tables exist in {db_path}")
|
||||||
|
verify_conn = sqlite3.connect(db_path)
|
||||||
|
verify_cursor = verify_conn.cursor()
|
||||||
|
verify_cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
||||||
|
tables = [row[0] for row in verify_cursor.fetchall()]
|
||||||
|
verify_conn.close()
|
||||||
|
print(f"🔍 DIAGNOSTIC: Tables found: {tables}")
|
||||||
|
|
||||||
|
|
||||||
def cleanup_dev_database(db_path: str = "data/trading_dev.db", data_path: str = "./data/dev_agent_data") -> None:
|
def cleanup_dev_database(db_path: str = "data/trading_dev.db", data_path: str = "./data/dev_agent_data") -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user