From 711ae5df73aebd7823c3b65b654ace4d64fb90d9 Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 1 Nov 2025 23:10:01 -0400 Subject: [PATCH] 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 --- api/database.py | 5 ++-- tests/unit/test_database_schema.py | 47 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/unit/test_database_schema.py diff --git a/api/database.py b/api/database.py index d6932a7..5da0c6a 100644 --- a/api/database.py +++ b/api/database.py @@ -85,7 +85,7 @@ def initialize_database(db_path: str = "data/jobs.db") -> None: CREATE TABLE IF NOT EXISTS jobs ( job_id TEXT PRIMARY KEY, 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, models 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, completed_at TEXT, total_duration_seconds REAL, - error TEXT + error TEXT, + warnings TEXT ) """) diff --git a/tests/unit/test_database_schema.py b/tests/unit/test_database_schema.py new file mode 100644 index 0000000..af11ab2 --- /dev/null +++ b/tests/unit/test_database_schema.py @@ -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()