Files
MoFin/scripts/check_3_dbs.py
T
hmo d5b8bec897 refactor: retire price_events.json completely — DB is the only store
User directive: no JSON, retire it fully, fix all related code.

Changes:
- price_monitor.py: record_event writes DB only; removed EVENTS_PATH/
  load_events/save_events entirely
- strategy_feedback.py: price events read from DB only (removed JSON fallback)
- system_health_check.py: removed price_events.json from file-check list,
  DB-only event stats (was showing 0/0 due to wrong-DB resolution)
- mo_config.py: removed dead price_events_path property (no callers)
- mofin_health.py: price_events freshness reads DB table (authoritative now)
- mofin_db.py: DATA_DIR/DB_PATH now ABSOLUTE (/home/hmo/MoFin/data) —
  was relative __file__.parent, so each hardlinked copy of mofin_db.py
  resolved to a DIFFERENT database (canonical vs web-dashboard vs
  profile-local third DB with 0 rows of everything except market_snapshots).
  This fragmentation was the real cause of health checks reading empty tables.
- Unified all 4 mofin_db copies (root/scripts/deploy/profile) via hardlink
- price_events.json archived to trashbox (fully backfilled: 6353 rows in DB)

Verified:
- record_event lands in DB only, JSON not recreated
- system_health_check: 历史事件 6353 / 今日事件 2965 (was 0/0)
- strategy_feedback + price_monitor full runs clean
2026-07-20 18:10:05 +08:00

24 lines
1.1 KiB
Python

import sqlite3
for label, path in [('canonical', '/home/hmo/MoFin/data/mofin.db'),
('profile-local', '/home/hmo/.hermes/profiles/position-analyst/scripts/data/mofin.db'),
('web-dashboard', '/home/hmo/web-dashboard/data/mofin.db')]:
try:
c = sqlite3.connect(path, timeout=5)
tables = [r[0] for r in c.execute("SELECT name FROM sqlite_master WHERE type='table'")]
print(f'=== {label}: {path}')
for t in ['price_events', 'holdings', 'live_prices', 'holding_strategies', 'market_snapshots']:
if t in tables:
cnt = c.execute(f"SELECT COUNT(*) FROM {t}").fetchone()[0]
try:
col = 'created_at' if t in ('price_events', 'market_snapshots') else 'updated_at'
last = c.execute(f"SELECT MAX({col}) FROM {t}").fetchone()[0]
except Exception:
last = '?'
print(f' {t}: {cnt} rows, last={last}')
else:
print(f' {t}: MISSING')
c.close()
except Exception as e:
print(f'{label}: ERROR {e}')
print()