batch drift 정합 — REL-001(BAT-001~016)·REL-002(BAT-017) released에 맞춰
batches/index 및 개별 index 상태를 release-candidate→released 동기화(17건).
README: bootstrap 문구 제거, dcy-007 엔드포인트(GET /trades·/pnl/realized) 추가,
planned-next 현행화. 코드 무변경.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VHtM5Ws1HKCKQ4JGi6GRb5
BAT-016's initial implementation passed only against mocked repositories and
broke on a real database. Two defects fixed:
1. insert_ledger_trade used `ON CONFLICT (portfolio_id, order_id, execution_id)
WHERE order_id IS NOT NULL` but portfolio_ledger is a TimescaleDB hypertable,
which cannot have that partial unique index (must include the partitioning
column recorded_at). The statement errored against Postgres. Replaced with
application-level idempotency: SELECT-before-insert inside the existing
`SELECT ... FOR UPDATE` portfolio row lock, which serializes concurrent
same-portfolio writes (race-safe). Duplicate returns current authoritative
portfolio state (dcy-006 OQ-4 b).
2. `with self._connect() as conn:` closes the shared psycopg3 connection on exit,
leaving the reused repository connection unusable. Switched to
`with conn.transaction():` (commits without closing).
Added tests/test_ledger_consolidation_integration.py — real-Postgres integration
tests (new / duplicate / negative-balance) that close the mock-only verification
gap. Full suite: 376 passed.
SDLC: REQ-036/037 CHG-20260605-03 reconcile OQ-7 (ii) (DB partial unique →
application-level idempotency) since the hypertable makes the DB constraint
infeasible. REQ-036/037/038 → Implemented; BAT-016 → release-candidate.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>