seawolf2357 commited on
Commit
3a85aa3
·
verified ·
1 Parent(s): db453f8

fix: defer npc_positions indexes + fallback to older backup on latest blob loss

Browse files
Files changed (1) hide show
  1. npc_trading.py +4 -1
npc_trading.py CHANGED
@@ -240,6 +240,8 @@ async def init_trading_db(db_path: str):
240
  """)
241
  await db.execute("CREATE INDEX IF NOT EXISTS idx_pos_agent ON npc_positions(agent_id, status)")
242
  await db.execute("CREATE INDEX IF NOT EXISTS idx_pos_ticker ON npc_positions(ticker, status)")
 
 
243
 
244
  # ★ 레버리지 컬럼 마이그레이션
245
  try:
@@ -2019,4 +2021,5 @@ async def get_npc_trade_history(db_path: str, agent_id: str) -> Dict:
2019
  'username': npc[0], 'identity': npc[1], 'mbti': npc[2], 'gpu': round(npc[3] or 0, 1),
2020
  'trades': trades,
2021
  'total_trades': len(trades),
2022
- }
 
 
240
  """)
241
  await db.execute("CREATE INDEX IF NOT EXISTS idx_pos_agent ON npc_positions(agent_id, status)")
242
  await db.execute("CREATE INDEX IF NOT EXISTS idx_pos_ticker ON npc_positions(ticker, status)")
243
+ await db.execute("CREATE INDEX IF NOT EXISTS idx_pos_closed ON npc_positions(status, closed_at)")
244
+ await db.execute("CREATE INDEX IF NOT EXISTS idx_pos_agent_closed ON npc_positions(agent_id, status, closed_at)")
245
 
246
  # ★ 레버리지 컬럼 마이그레이션
247
  try:
 
2021
  'username': npc[0], 'identity': npc[1], 'mbti': npc[2], 'gpu': round(npc[3] or 0, 1),
2022
  'trades': trades,
2023
  'total_trades': len(trades),
2024
+ }
2025
+