Files
trex-core/docs/srs/Data/req-006_postgresql-slot-persistence.md
T
genichinandClaude Opus 4.8 a4e263c8e7 Deliver BAT-002: slot-core daemon + HTTP intent API + PostgreSQL
Implement REQ-005~009 (dcy-002 slice 1) as an onion stack on top of the
BAT-001 pure domain:
- application: IntentService (admission + single-writer transition +
  intent_id idempotency via durable intent_log)
- adapters/persistence: PostgreSQLSlotRepository + PostgreSQLIntentStore +
  trex-core-owned migrations (daily_slot per Appendix A, daily_symbol_entries,
  slot_transition_log, intent_log) + in-memory intent store
- adapters/api: FastAPI /v1 (healthz, intents/buy|sell|{id}, slots, capacity)
- runtime: trex-core-daemon entrypoint with lifespan migrate+preallocate

Verification (against local PostgreSQL 18): 74 passed, ruff clean, domain
import sweep shows zero web/db deps (NFR-1), 20-thread concurrency admits
exactly the idle count (NFR-2), idempotent resubmit causes no double
transition (NFR-3), EXPECTED_SLOT_FIELDS<->information_schema drift test
(realizes dcy-001 OQ-2's deferred DB-side check), and a daemon E2E smoke.

Align all four baseline docs to the new daemon/API/persistence layers.
BAT-002 -> release-candidate; REQ-005~009 -> Implemented. Full async outbox,
broker execution, safety floor, and strategy daemons remain deferred to a
follow-up Discovery.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 13:46:08 +09:00

5.0 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 재참조로 충분.