feat: asset catalog API, 태그 DB 기초, 마이그레이션 3건 및 도메인/테스트 갱신 (2026-05-19)

This commit is contained in:
2026-05-19 22:15:55 +00:00
parent e2226e28b6
commit 158929b2d9
33 changed files with 2575 additions and 102 deletions
+36 -2
View File
@@ -33,6 +33,38 @@
- AuthToken :: issued client or service token with permission, runtime_id, and optional daemon_id binding
- BrokerCredential :: encrypted broker API credentials per user-broker pair
- LedgerTrade :: idempotent trade execution record keyed by (asset_id, order_id, execution_id)
- Asset :: catalog entry representing a tradeable asset; portfolios reference assets via FK
## Entity: `Asset`
- Purpose: represent a tradeable asset in the catalog; serves as FK anchor for portfolios
- Source of Truth: assets table; managed exclusively via admin CLI / admin API
- Lifecycle: created → optionally deactivated; never deleted (portfolios reference it with RESTRICT FK)
### Key Fields
- asset_id :: uuid :: server-generated UUID primary key (gen_random_uuid())
- symbol :: text UNIQUE :: exchange symbol (e.g. 005930, BTC)
- markets :: text[] :: array of market codes the asset is listed on (e.g. ["KRX", "NASDAQ"])
- display_name :: text|null :: human-readable name for display
- status :: text :: "active" | "inactive"; only active assets can be referenced by new portfolios
### Uniqueness Constraints
- assets_symbol_key :: UNIQUE (symbol) :: one catalog entry per symbol
### Indexes
- idx_assets_markets_gin :: GIN index on markets array :: supports efficient array containment queries
### Relationships
- Portfolio :: portfolios.asset_id FK → assets.asset_id ON DELETE RESTRICT; one asset → many portfolios
### State Rules
- Only `status="active"` assets can be referenced when creating a new portfolio.
- Deactivated assets do not affect existing portfolios; only new creation is blocked.
## Entity: `Portfolio`
@@ -44,8 +76,8 @@
- portfolio_id :: uuid :: server-generated UUID primary key; assigned at creation and never changed; BAT-006 migrated all pre-existing TEXT portfolio_id values to UUIDs
- name :: text :: human-readable portfolio name; unique per owner_user_id; validated against [a-zA-Z0-9._:-]{1,100}
- symbol :: text :: traded asset symbol for the portfolio
- market :: text|null :: market identifier for the asset (e.g., exchange code); added by migration 20260502_0014
- asset_id :: uuid :: FK → assets.asset_id; catalog reference for the traded asset; BAT-001 migrated symbol/market columns to this FK
- symbol :: text :: display symbol populated via JOIN on assets (read-only, not stored in portfolios)
- owner_user_id :: text|null :: owning user reference for attribution and authorization
- active_strategy_id :: text|null :: currently selected strategy-set reference
- cash_balance :: double precision :: current cash snapshot after the latest ledger event
@@ -58,6 +90,7 @@
### Relationships
- Asset :: asset_id FK ties each portfolio to exactly one catalog asset
- User :: owner_user_id links a portfolio to its owning user when ownership is assigned
- Daemon :: managed_by_daemon_id links a portfolio to exactly one daemon; NULL means unassigned
- StrategySet :: active_strategy_id and avabile_strategies connect reusable strategy definitions
@@ -242,6 +275,7 @@
## Change Log
- 2026-05-19 KST: bat-002 — REQ-015: added Entity: Asset (asset catalog with symbol UNIQUE, markets[], status); updated Portfolio.asset_id FK and symbol/market field notes.
- 2026-05-13 KST: bat-010 — REQ-009/023/028: added Entity: Daemon; added portfolios.managed_by_daemon_id; added auth_tokens.daemon_id; updated AuthToken State Rules (runtime_id vs daemon_id distinction, fail-closed policy); updated Portfolio Relationships; updated Model Summary.
- 2026-05-11 KST: bat-008 — REQ-011 AC-2: added portfolios.market column; added Entity: AuthToken (runtime_id field); added Entity: BrokerCredential; added Entity: LedgerTrade; updated Model Summary.
- 2026-05-11 KST: bat-006 — portfolios.portfolio_id changed to server-generated UUID PK; name column added with UNIQUE (owner_user_id, name) constraint; uq_portfolios_owner_name constraint documented; state rules updated.