mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-10 20:57:25 -04:00
feat(db): add downloading_data status and warnings column
Add support for: - downloading_data job status for visibility during data prep - warnings TEXT column for storing job-level warnings (JSON array) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -85,7 +85,7 @@ def initialize_database(db_path: str = "data/jobs.db") -> None:
|
|||||||
CREATE TABLE IF NOT EXISTS jobs (
|
CREATE TABLE IF NOT EXISTS jobs (
|
||||||
job_id TEXT PRIMARY KEY,
|
job_id TEXT PRIMARY KEY,
|
||||||
config_path TEXT NOT NULL,
|
config_path TEXT NOT NULL,
|
||||||
status TEXT NOT NULL CHECK(status IN ('pending', 'running', 'completed', 'partial', 'failed')),
|
status TEXT NOT NULL CHECK(status IN ('pending', 'downloading_data', 'running', 'completed', 'partial', 'failed')),
|
||||||
date_range TEXT NOT NULL,
|
date_range TEXT NOT NULL,
|
||||||
models TEXT NOT NULL,
|
models TEXT NOT NULL,
|
||||||
created_at TEXT NOT NULL,
|
created_at TEXT NOT NULL,
|
||||||
@@ -93,7 +93,8 @@ def initialize_database(db_path: str = "data/jobs.db") -> None:
|
|||||||
updated_at TEXT,
|
updated_at TEXT,
|
||||||
completed_at TEXT,
|
completed_at TEXT,
|
||||||
total_duration_seconds REAL,
|
total_duration_seconds REAL,
|
||||||
error TEXT
|
error TEXT,
|
||||||
|
warnings TEXT
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|||||||
47
tests/unit/test_database_schema.py
Normal file
47
tests/unit/test_database_schema.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import pytest
|
||||||
|
import sqlite3
|
||||||
|
from api.database import initialize_database, get_db_connection
|
||||||
|
|
||||||
|
def test_jobs_table_allows_downloading_data_status(tmp_path):
|
||||||
|
"""Test that jobs table accepts downloading_data status."""
|
||||||
|
db_path = str(tmp_path / "test.db")
|
||||||
|
initialize_database(db_path)
|
||||||
|
|
||||||
|
conn = get_db_connection(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Should not raise constraint violation
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at)
|
||||||
|
VALUES ('test-123', 'config.json', 'downloading_data', '[]', '[]', '2025-11-01T00:00:00Z')
|
||||||
|
""")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Verify it was inserted
|
||||||
|
cursor.execute("SELECT status FROM jobs WHERE job_id = 'test-123'")
|
||||||
|
result = cursor.fetchone()
|
||||||
|
assert result[0] == "downloading_data"
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
def test_jobs_table_has_warnings_column(tmp_path):
|
||||||
|
"""Test that jobs table has warnings TEXT column."""
|
||||||
|
db_path = str(tmp_path / "test.db")
|
||||||
|
initialize_database(db_path)
|
||||||
|
|
||||||
|
conn = get_db_connection(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Insert job with warnings
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at, warnings)
|
||||||
|
VALUES ('test-456', 'config.json', 'completed', '[]', '[]', '2025-11-01T00:00:00Z', '["Warning 1", "Warning 2"]')
|
||||||
|
""")
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
# Verify warnings can be retrieved
|
||||||
|
cursor.execute("SELECT warnings FROM jobs WHERE job_id = 'test-456'")
|
||||||
|
result = cursor.fetchone()
|
||||||
|
assert result[0] == '["Warning 1", "Warning 2"]'
|
||||||
|
|
||||||
|
conn.close()
|
||||||
Reference in New Issue
Block a user