fix: SQLite UNIQUE constraint on forward_curve_data — expressions not allowed
Replace UNIQUE(asset, DATE(fetched_at)) with dedicated fetch_date column + UNIQUE(asset, fetch_date). SQLite prohibits function calls in inline UNIQUE/PRIMARY KEY constraints. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user