mirror of
https://github.com/tiennm99/miti99bot-js.git
synced 2026-05-15 17:53:20 +00:00
99cd8449ec
Replaces the originally-planned SQL-pattern dispatcher with a direct refactor:
trading/history.js + retention.js call MongoTradesStore methods explicitly
instead of routing strings through a regex dispatcher. Cleaner abstraction;
eliminates the "7th SQL statement silently breaks" risk flagged in code-review.
- src/db/mongo-trades-store.js: 6 explicit methods (insert, byUser,
distinctUsers, oldRowsForUser, oldRows, deleteByIds). Lazy index init
for (user_id, ts desc), (ts desc), and sparse (legacy_id).
- src/db/mongo-sql-store.js: thin SqlStore shim returning {changes:1,
last_row_id:0} (number, NOT hex) to satisfy the existing
tests/db/create-sql-store.test.js:48-52 contract. Exists purely for
factory branching; trading code calls MongoTradesStore directly.
Unsupported SQL throws loud.
- trading/history.js + retention.js + index.js: accept optional
tradesStore in init args. Falls back to existing D1 sql path when
tradesStore absent — keeps trading working on D1 until Phase 04
wires dual-write.
- legacy_id: null on runtime inserts. Sparse index + field reserved
for backfill (Phase 05) to preserve original D1 integer IDs for
historical join-ability.
Pre-refactor grep gates (all PASS):
- exactly 6 SQL statements in src/modules/trading/
- zero arithmetic on .id (.id [+-*/<>])
- last_row_id consumed by zero callers in trading
Tests: 529 → 577 (+48). Lint clean.