feat(slot): BAT-027 M1 — additive 영구 슬롯 필드(instance_key, retired_at) + 마이그레이션 009 (dcy-020/REQ-056)

안 B(점진/additive-first)의 1단계. 라이브 영향·cascade 없이 자산 영구 슬롯 토대의
스키마/모델 필드만 additive 추가.

- Slot.instance_key(기본 "default")·retired_at 추가 + EXPECTED_SLOT_FIELDS 정합
- 마이그레이션 009: instance_key NOT NULL DEFAULT 'default', retired_at,
  부분 UNIQUE(instance_key, portfolio_id) WHERE portfolio_id IS NOT NULL (멱등)
- postgresql _SLOT_COLUMNS/_row_to_slot/update_slot 매핑(row[19]/[20])
- entry_count/trading_date 컬럼은 유지(drop 은 cutover BAT-δ)

검증: 전체 375 passed / 35 skipped, ruff clean (additive — cascade 무파손).
M2(상태머신 inactive 별칭+인스턴스 lock)/M3(소비처 cascade)는 후속.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-10 10:42:24 +09:00
co-authored by Claude Opus 4.8
parent 4e92134c28
commit 86c892aa0c
4 changed files with 46 additions and 8 deletions
+6 -3
View File
@@ -30,7 +30,7 @@ _SLOT_COLUMNS = (
"slot_id, trading_date, status, symbol, qty, avg_price, limit_price, "
"allocated_capital, order_id, strategy_id, broker_order_id, portfolio_id, "
"sell_strategy_id, forced_close_at, stop_loss_price, take_profit_price, "
"created_at, updated_at, entry_count"
"created_at, updated_at, entry_count, instance_key, retired_at"
)
@@ -139,14 +139,15 @@ class PostgreSQLSlotRepository:
"limit_price=%s, allocated_capital=%s, order_id=%s, strategy_id=%s, "
"broker_order_id=%s, portfolio_id=%s, sell_strategy_id=%s, "
"forced_close_at=%s, stop_loss_price=%s, take_profit_price=%s, "
"entry_count=%s, updated_at=%s WHERE slot_id=%s",
"entry_count=%s, instance_key=%s, retired_at=%s, "
"updated_at=%s WHERE slot_id=%s",
(
slot.status.value, slot.symbol, slot.qty, slot.avg_price,
slot.limit_price, slot.allocated_capital, slot.order_id,
slot.strategy_id, slot.broker_order_id, slot.portfolio_id,
slot.sell_strategy_id, slot.forced_close_at,
slot.stop_loss_price, slot.take_profit_price,
slot.entry_count,
slot.entry_count, slot.instance_key, slot.retired_at,
slot.updated_at or datetime.now(tz=timezone.utc), slot.slot_id,
),
)
@@ -276,6 +277,8 @@ class PostgreSQLSlotRepository:
created_at=row[16],
updated_at=row[17],
entry_count=int(row[18]) if row[18] is not None else 0,
instance_key=row[19] if row[19] is not None else "default",
retired_at=row[20],
)