# req-056: 자산 영구 슬롯 스키마 재설계 + 마이그레이션 - Status: Implemented - Type: Data - Priority: High - Owner: project maintainers ## Intent - 익명 슬롯 풀(`daily_slot` 일일 익명 행)을 portfolio-hub universe 자산과 1:1 대응하는 **영구 슬롯**으로 전환하기 위해, `daily_slot` 스키마를 자산 키·인스턴스 스코프·영속 모델로 재설계한다. (dcy-020 FR-1/OQ-3/OQ-7) ## Requirement - `daily_slot` 을 영구 슬롯으로 재설계한다: `portfolio_id` 를 **NOT NULL 영구 키**로, `instance_key` 컬럼 추가, **`UNIQUE(instance_key, portfolio_id)`**, 은퇴 마커 `retired_at`(또는 `universe_detached`) 추가. `trading_date`(슬롯 정체성)·`entry_count`(dcy-019) 컬럼은 제거하고, trading_date 는 이벤트/원장/정책의 시간 속성으로만 둔다. 멱등 마이그레이션(009) + `EXPECTED_SLOT_FIELDS` 계약 + persistence flat 매핑 + `data-model.md` 를 같은 변경 묶음으로 정합한다. slot-scoped 테이블(slot_transition_log/intent_log/ledger_outbox/snapshot_pause/killswitch_exclusion)도 `instance_key` 스코프화한다. ## Acceptance Criteria 1. Given 마이그레이션 적용, When `daily_slot` 스키마를 확인, Then `portfolio_id NOT NULL`, `instance_key` 존재, `UNIQUE(instance_key, portfolio_id)`, `retired_at` 존재, 슬롯 정체성 `trading_date`·`entry_count` 부재. 2. Given `EXPECTED_SLOT_FIELDS` 계약 가드, When 도메인 필드셋과 information_schema 를 비교, Then 영구 슬롯 필드셋과 일치한다. 3. Given 같은 `(instance_key, portfolio_id)` 행 중복 삽입, When insert, Then UNIQUE 제약으로 거부된다. 4. Given slot-scoped 테이블, When 스키마 확인, Then 각 테이블이 `instance_key` 로 스코프되어 인스턴스 간 행이 섞이지 않는다. ## Impacted Area - Docs: docs/data-model.md (daily_slot 재설계), dcy-020 - Modules: trex_core/adapters/persistence/sql/009_*.sql(신규), trex_core/adapters/persistence/postgresql.py, trex_core/domain/slot/models.py - Tests: tests/domain/slot/test_contract.py, tests/adapters/persistence/test_migration_and_drift.py ## Notes - 기존 REQ 영향(change-req 동반): REQ-002(Slot 필드/EXPECTED_SLOT_FIELDS 재정의), REQ-006(persistence 스키마), REQ-003(계약 가드). dcy-019 `entry_count`·dcy-014 `trading_date` 슬롯키 제거는 그 REQ들의 change-req 로 함께 처리. - 라이브 데이터 일일행→영구행 전환은 REQ-064(cutover)에서 다룬다(본 REQ 는 목표 스키마 정의). - 출처: dcy-020 FR-1, OQ-3, OQ-7. ## Change Log ### CHG-20260610-01 - Date: 2026-06-10 - Author: Justin Ko #### Change Summary - dcy-020 FR-1/OQ-3/OQ-7 로부터 최초 생성(Proposed). 영구 슬롯 스키마(자산 키·instance_key·UNIQUE 복합·retired_at, trading_date/entry_count 제거). #### Intent - 익명 풀 daily_slot → 자산 1:1 영구 슬롯 스키마 전환을 backlog 로 정규화. #### Acceptance Criteria Delta - Added: - 영구 슬롯 스키마/UNIQUE(instance_key, portfolio_id)/계약 가드/slot-scoped 테이블 instance 스코프 4개 기준 - Updated: 없음 - Removed: 없음 #### Impacted Area Delta - Docs: docs/data-model.md - Modules: sql/009_*, postgresql.py, domain/slot/models.py - Tests: test_contract.py, test_migration_and_drift.py #### Delivery Trace Delta - Batches: none (batch 편성 전) - Releases: none #### Revalidation Impact - Reverification Needed: no - Existing Implementation Invalidated: no (목표 스키마 정의; 실데이터 전환은 REQ-064) - Status Recommendation: keep-current - Follow-up Action: confirm-req → suggest-batch-reqs/draft-batch. REQ-002/003/006 change-req 동반. #### Validation Plan - 마이그레이션 적용 후 스키마/UNIQUE/계약 가드 + drift 테스트 green. ### CHG-20260610-02 - Date: 2026-06-10 - Author: Justin Ko #### Change Summary - Status Proposed → Approved (confirm-req). 필수 필드·구체 AC 충족, source dcy-020(confirmed, handoff 승인)과 모순 없음. #### Intent - delivery input 으로 승격. #### 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. #### Validation Plan - 승인 후 batch planning 에서 본 REQ AC 를 검증 기준으로 사용. ### CHG-20260610-IMPL - Date: 2026-06-10 - Author: Justin Ko - Type: status - Summary: Approved → Implemented (confirm-req-implemented). 근거: BAT-027(토대)+BAT-030(컬럼 drop·promote-unique) — 모든 AC 가 release-candidate 배치 verification 의 evidence 와 연결됨(단위 367/PG 29/MQ 21 passed + run-the-app 자산 중심 e2e). Blocking Issues 없음.