From 655f2a66ebdf919471a2d481cfe9b447e54426bb Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 3 Nov 2025 23:06:19 -0500 Subject: [PATCH] fix: enable foreign key constraints and ensure jobs table prerequisite - Add PRAGMA foreign_keys = ON at the beginning of create_trading_days_schema() - Create jobs table if it doesn't exist as a prerequisite for the foreign key constraint - Ensures referential integrity is properly enforced for the trading_days table --- api/migrations/001_trading_days_schema.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api/migrations/001_trading_days_schema.py b/api/migrations/001_trading_days_schema.py index 630f188..6e75172 100644 --- a/api/migrations/001_trading_days_schema.py +++ b/api/migrations/001_trading_days_schema.py @@ -13,6 +13,26 @@ def create_trading_days_schema(db: "Database") -> None: Args: db: Database instance to apply migration to """ + # Enable foreign key constraint enforcement + db.connection.execute("PRAGMA foreign_keys = ON") + + # Create jobs table if it doesn't exist (prerequisite for foreign key) + db.connection.execute(""" + CREATE TABLE IF NOT EXISTS jobs ( + job_id TEXT PRIMARY KEY, + config_path TEXT NOT NULL, + 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, + started_at TEXT, + updated_at TEXT, + completed_at TEXT, + total_duration_seconds REAL, + error TEXT, + warnings TEXT + ) + """) # Create trading_days table db.connection.execute("""