修复复盘交易记录并发迁移 prev_entry_tf 导致加载失败。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -87,6 +87,7 @@ def init_options_review_tables(conn: sqlite3.Connection) -> None:
|
|||||||
strategy_tag TEXT,
|
strategy_tag TEXT,
|
||||||
direction_view TEXT,
|
direction_view TEXT,
|
||||||
entry_logic TEXT,
|
entry_logic TEXT,
|
||||||
|
prev_entry_tf TEXT,
|
||||||
exit_reason TEXT,
|
exit_reason TEXT,
|
||||||
followed_plan TEXT,
|
followed_plan TEXT,
|
||||||
mistake_tags TEXT,
|
mistake_tags TEXT,
|
||||||
@@ -141,5 +142,13 @@ def _ensure_column(conn: sqlite3.Connection, table: str, col: str, typedef: str)
|
|||||||
names.add(str(r["name"]))
|
names.add(str(r["name"]))
|
||||||
except (TypeError, KeyError, IndexError):
|
except (TypeError, KeyError, IndexError):
|
||||||
names.add(str(r[1]))
|
names.add(str(r[1]))
|
||||||
if col not in names:
|
if col in names:
|
||||||
|
return
|
||||||
|
try:
|
||||||
conn.execute(f"ALTER TABLE {table} ADD COLUMN {col} {typedef}")
|
conn.execute(f"ALTER TABLE {table} ADD COLUMN {col} {typedef}")
|
||||||
|
except sqlite3.OperationalError as e:
|
||||||
|
# 并发首启时多个请求同时 ADD,后者报 duplicate column — 可忽略
|
||||||
|
msg = str(e).lower()
|
||||||
|
if "duplicate column" in msg or "already exists" in msg:
|
||||||
|
return
|
||||||
|
raise
|
||||||
|
|||||||
@@ -326,6 +326,9 @@ def register_options_review_routes(app: Flask, cfg: dict[str, Any], repo_root: s
|
|||||||
"pages": pages,
|
"pages": pages,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[options_review_trades] {e}", flush=True)
|
||||||
|
return jsonify({"ok": False, "msg": f"加载交易记录失败: {e}"}), 500
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
@@ -447,6 +450,10 @@ def register_options_review_routes(app: Flask, cfg: dict[str, Any], repo_root: s
|
|||||||
)
|
)
|
||||||
stats["source_types"] = list(SOURCE_TYPES)
|
stats["source_types"] = list(SOURCE_TYPES)
|
||||||
stats["source_labels"] = SOURCE_LABELS
|
stats["source_labels"] = SOURCE_LABELS
|
||||||
|
stats["ok"] = True
|
||||||
return jsonify(stats)
|
return jsonify(stats)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[options_review_stats] {e}", flush=True)
|
||||||
|
return jsonify({"ok": False, "msg": f"加载统计失败: {e}"}), 500
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user