- add ledger consolidation migration and remove ledger_trades usage - return portfolio state after v1 ledger trade writes - deprecate legacy buy/sell endpoints with deprecation headers - add BAT-016, DCY-006, and REQ-036~038 documentation - update repository models and tests for unified ledger entries
2.4 KiB
2.4 KiB
BAT-016 Implementation
- Status: implemented
- Batch: BAT-016
Plan Summary
- 순서: REQ-036(마이그레이션 + ensure_schema) → REQ-037(repository/도메인/응답/회계) → REQ-038(deprecated)
- 각 REQ 후 부분 회귀, batch 마지막 통합 회귀를 수행했다.
Changed Files
migrations/versions/20260605_0025_ledger_consolidation.pyapp/repositories/postgres.pyapp/repositories/portfolio_repository.pyapp/domain/models.pyapp/domain/services.pycall-site compatible model usage retained throughLedgerEntry.actioncompatibilityapp/schemas/v1.pyapp/api/v1_portfolios.pyapp/api/portfolios.pytests/test_v1_portfolios_ledger.pytests/test_v1.pytests/test_daemon_assignment.pytests/test_auth.py
Execution Log
portfolio_ledgerschema was consolidated to carry trade-write identifiers/state directly:ledger_entry_id,order_id,execution_id,side,executed_at,cash_balance_after, andasset_quantity_after.- Legacy
ledger_tradesreferences were removed from application code;ensure_schema()now migrates oldactiondata intoside, dropsaction, and dropsledger_tradeswhen present. LedgerEntrybecame the canonical domain object for recent trades and authoritative ledger-trade writes.POST /v1/portfolios/{portfolio_id}/ledger/tradesnow writes toportfolio_ledger, supports idempotent lookup by broker identifiers, computes cash/security balances, and returns accounting state.- Legacy
/portfolios/{portfolio_id}/buyand/portfolios/{portfolio_id}/sellroutes were markeddeprecated=Trueand emitDeprecation: trueon legacy responses/errors. - Regression tests were updated to assert the consolidated model and deprecation header behavior.
Validation
- Targeted regression:
.venv/bin/python -m pytest -q tests/test_domain_services.py tests/test_v1_portfolios_ledger.py tests/test_daemon_assignment.py tests/test_v1.py- Result:
47 passed in 3.66s
- Full suite:
.venv/bin/python -m pytest -q- Result:
373 passed, 3 warnings in 14.78s
Remaining Risks
- Timescale hypertable constraints can require time-column-aware unique/primary indexes. The runtime consolidation avoids unsupported primary/unique constraints on
portfolio_ledger; idempotency is enforced in repository logic by looking up(portfolio_id, order_id, execution_id)before insert.