Files
trex-core/docs/srs/Data/req-006_postgresql-slot-persistence.md
T
genichinandClaude Opus 4.8 cc28e1fba5 fix(execution): dcy-012 매도 가격 버그 정정 — slot entry_price→limit_price rename (BAT-016)
매도(sell) 주문이 현재가가 아닌 매수가(entry_price) 지정가로 나가던 버그(issue #10)
정정. 슬롯의 매수 전용 entry_price 를 side 무관 "현재 pending 주문 지정가"
limit_price 로 내부 rename 하고, pending 이탈(→holding/→closed) 시 clear 해
매수 지정가가 매도로 누수되는 경로를 구조적으로 제거.

거버넌스: 전부 change-req (신규 REQ 없음, dcy-012 OQ-3).
- REQ-002: Slot entry_price→limit_price rename + clear-on-exit 생애주기
- REQ-006: daily_slot 컬럼 rename 마이그레이션 006 (idempotent) + persistence 매핑
- REQ-013: _dispatch 가 slot.limit_price 단일 필드로 가격/주문유형 결정
- REQ-007: SellIntent/sell payload optional limit_price + _admit_sell 운반
- REQ-036: SlotService.sell optional 가격 → 자율 매도(safety-sell/kill-switch) 시장가
- REQ-003: 컬럼 계약/드리프트 가드 limit_price 반영
- REQ-015: runtime-flows/interface-contract/data-model 정합

매도 정책(OQ-1 하이브리드): 가격 지정→지정가("00"), 미지정→시장가("01").
자율 매도는 가격 미전달 → 항상 시장가 (손절 미체결 pending_sell 갇힘 방지, issue #9 연계).

검증: 단위 286 passed/32 skipped, 인프라 게이트(PG+RabbitMQ) 318 passed, ruff clean.
신규 test_sell_pricing(recording broker)로 지정가 매수 슬롯의 매도가 매수가
재사용 안 함을 직접 검증. BAT-016 release-candidate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 13:41:46 +09:00

6.5 KiB

req-006: PostgreSQL SlotRepository 영속화 + 스키마

  • Status: Implemented
  • Type: Data
  • Priority: High
  • Owner: project maintainers

Intent

  • 코어가 daily_slot 을 durable 단일 writer 로 소유하도록 SlotRepository 의 PostgreSQL 구현과 스키마를 추가한다. dcy-001 부록 A 컬럼 계약을 영속화에서 실제로 충족시킨다.

Requirement

  • SlotRepository Protocol 의 psycopg 기반 PostgreSQL 구현을 추가하고, trex-core 소유의 신규 마이그레이션으로 daily_slot(부록 A 16컬럼)·daily_symbol_entries·slot_transition_log·intent_log 테이블을 생성한다. advisory lock 을 실제 pg_advisory_xact_lock 으로 구현한다. EXPECTED_SLOT_FIELDS ↔ daily_slot 실제 컬럼(information_schema) 드리프트 테스트를 동반한다.

Acceptance Criteria

  1. Given PostgreSQL 백엔드, When 마이그레이션 적용, Then daily_slot·daily_symbol_entries·slot_transition_log·intent_log 가 생성되고 daily_slot 컬럼이 부록 A(16컬럼)와 일치한다.
  2. Given PostgreSQL SlotRepository, When SlotService 를 이 repo 로 구동, Then 도메인 단위/통합테스트가 in-memory 와 동일하게 통과한다(전이/재진입+1/race 감지).
  3. Given 드리프트 테스트, When EXPECTED_SLOT_FIELDS ↔ information_schema 대조, Then 일치하고 컬럼 누락 시 실패한다(dcy-001 OQ-2 DB-side 검사 실현).
  4. Given 상태 변경, When transit_slot, Then pg_advisory_xact_lock 하 단일 트랜잭션으로 직렬화되고 lock 보유 중 외부 I/O 가 없다.

Impacted Area

  • Docs: docs/data-model.md(테이블/계약), dcy-001 부록 A(기준)
  • Modules: trex_core/ 하위 persistence 어댑터(psycopg) + 마이그레이션 SQL; 도메인 패키지는 무의존 유지(NFR-1)
  • Tests: PostgreSQL repo 통합테스트 + 드리프트 테스트

Notes

  • 스키마는 부록 A 단일 기준, orbit-v2 DDL 참조(dcy-002 OQ-4). daily_slot_archive/prune 는 범위 밖.
  • NFR-1(도메인 순수성) 일부 흡수: psycopg 의존은 persistence 어댑터에만, 도메인 import 스윕 0 유지.
  • REQ-005(런타임) 선행 권장, REQ-007/008(API)의 단일 writer 근거.
  • 출처: dcy-002 FR-5.

Change Log

CHG-20260603-01

  • Date: 2026-06-03
  • Author: Justin Ko

Change Summary

  • dcy-002 FR-5 로부터 최초 생성(Proposed). NFR-1 일부 흡수.

Intent

  • PostgreSQL 영속화 + 스키마 + 드리프트 테스트 요구사항을 backlog 로 정규화.

Acceptance Criteria Delta

  • Added:
    • 마이그레이션/컬럼 일치, repo 구동 테스트, 드리프트 테스트, advisory lock 4개 기준
  • Updated:
    • 없음
  • Removed:
    • 없음

Impacted Area Delta

  • Docs:
    • docs/data-model.md, dcy-001 부록 A
  • Modules:
    • persistence 어댑터(psycopg) + 마이그레이션 SQL
  • Tests:
    • PostgreSQL repo 통합테스트 + 드리프트 테스트

Delivery Trace Delta

  • Batches:
    • none
  • Releases:
    • none

Revalidation Impact

  • Reverification Needed: no
  • Existing Implementation Invalidated: no
  • Status Recommendation: keep-current
  • Follow-up Action: confirm-req 후 batch 편성

Validation Plan

  • PostgreSQL 통합테스트(가능 시) + 드리프트 테스트로 검증.

CHG-20260603-02

  • Date: 2026-06-03
  • Author: Justin Ko

Change Summary

  • Status Proposed → Approved (confirm-req).

Intent

  • 승인 게이트(필수 필드·구체 AC·blocker 없음) 충족, source dcy-002(confirmed, handoff 승인)와 모순 없음 확인.

Acceptance Criteria Delta

  • Added:
    • 없음
  • Updated:
    • 없음
  • Removed:
    • 없음

Impacted Area Delta

  • Docs:
    • docs/srs/index.md (Register 상태 Approved)
  • Modules:
    • 없음
  • Tests:
    • 없음

Delivery Trace Delta

  • Batches:
    • none (batch 편성 전)
  • Releases:
    • none

Revalidation Impact

  • Reverification Needed: no
  • Existing Implementation Invalidated: no
  • Status Recommendation: keep-current
  • Follow-up Action: suggest-batch-reqs / draft-batch 로 delivery batch 편성

Validation Plan

  • 승인 후 batch planning 에서 본 REQ 의 Acceptance Criteria 를 검증 기준으로 사용.

CHG-20260603-03

  • Date: 2026-06-03
  • Author: Justin Ko

Change Summary

  • Status Approved → Implemented (confirm-req-implemented, 근거 batch BAT-002 release-candidate).

Intent

  • BAT-002 verification.md 의 acceptance mapping + evidence(pytest 74 pass / PG 통합 / 데몬 E2E)로 모든 AC 충족 → 구현 완료 동기화.

Acceptance Criteria Delta

  • Added:
    • 없음
  • Updated:
    • 없음
  • Removed:
    • 없음

Impacted Area Delta

  • Docs:
    • docs/srs/index.md (Register Implemented)
  • Modules:
    • 없음
  • Tests:
    • 없음

Delivery Trace Delta

  • Batches:
    • BAT-002 (release-candidate)
  • Releases:
    • none

Revalidation Impact

  • Reverification Needed: no
  • Existing Implementation Invalidated: no
  • Status Recommendation: keep-current
  • Follow-up Action: draft-release 로 release 편성

Validation Plan

  • BAT-002 verification evidence 재참조로 충분.

CHG-20260608-01

  • Date: 2026-06-08
  • Author: Justin Ko

Change Summary

  • (change-req, dcy-012) daily_slot.entry_price → limit_price 컬럼 rename 마이그레이션(006_rename_entry_price_to_limit_price.sql, idempotent DO-block) + persistence 매핑(_SLOT_COLUMNS/update_slot/_row_to_slot) 갱신. 순수 rename 으로 기존 행 데이터 보존(S-3). BAT-016 재구현·재검증 완료 → Implemented 유지.

Intent

  • 도메인 필드 rename(REQ-002)을 영속 스키마/매핑에 반영하면서 기존 데이터를 보존.

Acceptance Criteria Delta

  • Updated:
    • daily_slot 컬럼 entry_price → limit_price (마이그레이션 006, 데이터 보존). persistence read/write 매핑 동기화.

Impacted Area Delta

  • Modules: trex_core/adapters/persistence/postgresql.py, trex_core/adapters/persistence/sql/006_rename_entry_price_to_limit_price.sql(신규)
  • Tests: tests/adapters/persistence/test_migration_and_drift.py(컬럼 계약 = limit_price, 마이그레이션 idempotent)

Delivery Trace Delta

  • Batches: BAT-016
  • Releases: none

Revalidation Impact

  • Reverification Needed: yes (BAT-016 에서 완료)
  • Existing Implementation Invalidated: yes (entry_price 컬럼/매핑)
  • Status Recommendation: Implemented (change-req → BAT-016 재검증)
  • Follow-up Action: confirm-req-implemented(BAT-016).

Validation Plan

  • BAT-016: PG 게이트 마이그레이션 round-trip + 컬럼 계약(limit_price) + idempotency.