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()