diff --git a/backend/services/database.py b/backend/services/database.py index ac3a336..364eae8 100644 --- a/backend/services/database.py +++ b/backend/services/database.py @@ -729,8 +729,9 @@ def init_db(): slope_pct REAL, structure TEXT NOT NULL DEFAULT 'unknown', months_spread INTEGER DEFAULT 3, + fetch_date TEXT NOT NULL DEFAULT (date('now')), fetched_at TEXT NOT NULL DEFAULT (datetime('now')), - UNIQUE(asset, DATE(fetched_at)) + UNIQUE(asset, fetch_date) )""") # Seed desk defaults (idempotent) @@ -4374,9 +4375,9 @@ def save_forward_curves(entries: List[Dict[str, Any]]) -> int: saved = 0 for e in entries: conn.execute("""INSERT INTO forward_curve_data - (asset, asset_class, front_price, far_price, slope_pct, structure, months_spread) - VALUES (?,?,?,?,?,?,?) - ON CONFLICT(asset, DATE(fetched_at)) DO UPDATE SET + (asset, asset_class, front_price, far_price, slope_pct, structure, months_spread, fetch_date) + VALUES (?,?,?,?,?,?,?,date('now')) + ON CONFLICT(asset, fetch_date) DO UPDATE SET front_price=excluded.front_price, far_price=excluded.far_price, slope_pct=excluded.slope_pct, structure=excluded.structure, fetched_at=datetime('now')""", @@ -4394,8 +4395,8 @@ def get_latest_forward_curves() -> List[Dict[str, Any]]: try: rows = conn.execute(""" SELECT * FROM forward_curve_data - WHERE (asset, DATE(fetched_at)) IN ( - SELECT asset, MAX(DATE(fetched_at)) FROM forward_curve_data GROUP BY asset + WHERE (asset, fetch_date) IN ( + SELECT asset, MAX(fetch_date) FROM forward_curve_data GROUP BY asset ) ORDER BY asset_class, asset""").fetchall() return [dict(r) for r in rows]