Asset Catalog Model Implementation (BAT-001): - Introduce assets table with UUID PK, symbol UNIQUE, markets TEXT[] array - Define MarketCode enum (KRX, NXT, SOR, NASDAQ, NYSE, UPBIT, BITHUMB) - Add Asset domain model with catalog properties - Implement asset CRUD protocols in portfolio_repository - Add PostgreSQL asset CRUD operations with GIN index on markets Portfolio Model Refactoring (REQ-011): - Add portfolios.asset_id UUID FK to assets(asset_id) ON DELETE RESTRICT - Remove portfolios.symbol and portfolios.market columns - Update Portfolio domain model to reference asset_id instead of symbol/market - Refactor all portfolio queries to JOIN assets catalog - Update all repository methods to use asset references Data Migration (REQ-014): - Create 20260519_0017 Alembic revision for assets table creation - Create 20260519_0018 Alembic revision for atomic data migration: * Extract unique symbol combinations from portfolios * Aggregate markets using ARRAY_AGG(DISTINCT market) * Populate assets catalog with extracted data * Update portfolios.asset_id to reference new assets * Remove legacy symbol/market columns in single transaction - Implement migration with rollback support Requirements Approved (REQ-001~008): - REQ-001~008 transitioned from Proposed to Approved - Complete tag model requirement set with implementation readiness New Requirements Approved (REQ-009~015): - REQ-009: assets table schema (approved, included in BAT-001) - REQ-010: admin asset catalog CRUD (approved, future BAT-002) - REQ-011: portfolios asset_id FK (approved, included in BAT-001) - REQ-012: portfolio create catalog validation (approved, future BAT-002) - REQ-013: GET /v1/assets token branching (approved, future BAT-002) - REQ-014: portfolios data migration (approved, included in BAT-001) - REQ-015: asset catalog baseline docs (approved) Code Changes: - app/domain/models.py: Add Asset model, MarketCode enum, Portfolio asset_id FK - app/repositories/portfolio_repository.py: Define asset CRUD protocol - app/repositories/postgres.py: Implement asset operations with full CRUD - app/api/v1_assets.py: Remove symbol/market direct references - app/cli/commands/portfolio.py: Update portfolio commands for asset references - app/schemas/portfolio.py: Update portfolio schema with asset_id - All portfolio operations throughout codebase: Use asset references Testing: - Add test_asset_catalog.py for asset CRUD operations - Verify REQ-009 AC-1~5 (asset catalog creation, lookup, uniqueness) - Verify REQ-011 AC-1~5 (FK constraint, portfolio asset reference) - Verify REQ-014 AC-1~6 (migration atomicity, data correctness, rollback) - Update existing tests for asset model usage Documentation: - Create BAT-001 batch documents (planning, design, implementation, verification) - Update dcy-001 with implementation details and confirmed architecture - Add 8 new requirement documents (REQ-009~015) - Update docs/discovery/index.md with batch entry Impact: - Database: assets catalog table, portfolios refactored to reference assets - Migration: 2 new Alembic revisions (0017 assets, 0018 portfolio migration) - API: Symbol/market now accessed through asset references - CLI: Portfolio commands require asset reference pattern - All existing portfolio data preserved and correctly migrated
3.0 KiB
3.0 KiB
BAT-001: asset catalog DB 기반 도입
- Status: verified
- Profile: standard
- Source Discovery: dcy-001
- Included REQ: REQ-009, REQ-011, REQ-014
- Excluded REQ: REQ-010, REQ-012, REQ-013, REQ-015 (→ BAT-002 예정)
Summary
- dcy-001의 핵심 DB 변경을 단일 delivery 단위로 묶는다.
assetscatalog 테이블을 신규 도입(REQ-009)하고,portfolios테이블을asset_id FK참조 구조로 재설계하며symbol/market컬럼을 제거(REQ-011)한다.- 기존 운영 데이터를 손실 없이
assetscatalog로 이전하고portfolios.asset_id를 채운 후 레거시 컬럼을 삭제하는 데이터 마이그레이션(REQ-014)을 원자적 Alembic revision으로 완성한다. - 이 batch 완료 후 admin CRUD API/CLI(REQ-010), portfolio 생성 검증(REQ-012), GET /v1/assets 분기 재작성(REQ-013) 착수가 가능해진다.
Scope
- In Scope:
assets테이블 Alembic revision (asset_id UUID PK, symbol UNIQUE, markets TEXT[], GIN index)MarketCodeEnum(KRX, NXT, SOR, NASDAQ, NYSE, UPBIT, BITTHUMB) —app/domain/models.pyAsset도메인 모델 —app/domain/models.py- asset CRUD Protocol 선언 —
app/repositories/portfolio_repository.py - asset CRUD Postgres 구현 —
app/repositories/postgres.py portfolios.asset_id UUID NOT NULL FK REFERENCES assets(asset_id) ON DELETE RESTRICT추가 Alembic revisionportfolios.symbol,portfolios.market컬럼 제거 Alembic revisionportfolios기존 데이터를assetscatalog로 이전하는 데이터 마이그레이션 Alembic revision (ARRAY_AGG(DISTINCT market), 단일 트랜잭션)Portfolio도메인 모델 symbol/market 제거, asset_id 추가 —app/domain/models.pyapp/repositories/postgres.pyportfolios 쿼리 — assets JOIN 반영, symbol/market 참조 제거- symbol/market 직접 참조 모듈 전수 수정 (app/api, app/cli, app/schemas)
tests/test_asset_catalog.py신규 — REQ-009 AC-15, REQ-011 AC-15, REQ-014 AC-1~6
- Out of Scope:
- admin asset CRUD HTTP API/CLI (→ REQ-010, BAT-002)
- pfhub portfolio create catalog 검증 (→ REQ-012, BAT-002)
- GET /v1/assets token-type 분기 재작성 (→ REQ-013, BAT-002)
- baseline 문서 갱신 (→ REQ-015, BAT-002)
- tag 모델 관련 모든 변경 (→ dcy-002 batches)
Documents
- Planning: planning.md
- Design: design.md
- Implementation: implementation.md
- Verification: verification.md
Notes
- R-2(High): 구현 착수 전
grep -rn "\.symbol\|\.market" app/전수 조사 필수 — 6개 이상 모듈에 참조 잔존 가능성 - REQ-011 schema 변경과 REQ-014 데이터 이전은 같은 Alembic revision 또는 순서 보장된 revision 시퀀스로 처리해야 한다 (REQ-014 Notes)
- 운영 데이터 migration이 포함되므로 로컬 DB에서 사전 dry-run 검증 권장
- dcy-002 REQ-002, REQ-003는 이 batch 완료 후에 착수 가능 (portfolios 재설계 선행 필요)