Core Changes: - Migrate portfolio_id from string to UUID in schema and repository layer - Update portfolio CLI commands to use name+user combination for identification - Update HTTP API to accept portfolio_id as UUID path parameter - Implement portfolio ownership validation in repository queries Requirements Completed (REQ-016 to REQ-019): - REQ-016: portfolios table UUID schema migration with data migration script - REQ-017: CLI portfolio commands with name+user identification - REQ-018: HTTP API portfolio path parameters and v1 asset_id UUID returns - REQ-019: Portfolio UUID baseline documentation updates BAT-001 Re-verification: - REQ-004~010 marked as Implemented after verification evidence validation - All v1 API endpoints verified with comprehensive test coverage Documentation Updates: - Update data-model.md with portfolio UUID structure - Update interface-contract.md with UUID path parameters - Update runtime-flows.md with ownership-based resolution flows - Update project-structure.md with database layer changes - Add migration script for portfolio UUID transition Testing: - Add test_portfolio_uuid.py for migration validation - Update test_cli.py and test_portfolio_ownership.py for ownership checks
3.7 KiB
3.7 KiB
BAT-007 Implementation
- Status: completed
- Batch: BAT-007
Plan Summary
- REQ-002:
app/repositories/postgres.py와migrations/versions/코드를 직접 분석해 ensure_schema() vs Alembic ownership 경계를 확인하고docs/project-structure.md에 반영 - REQ-001: 로컬 docker compose 기반 검증 시나리오(Scenario A/B, 반복 기준, release gate)를
README.md와docs/runtime-flows.md에 반영 - REQ-003: README runbook + docs/project-structure.md, docs/runtime-flows.md baseline 갱신
코드 변경 없음. 분석 결과 기존 IF NOT EXISTS guard와 bootstrap_or_upgrade_to_head() 메커니즘이 ownership 충돌을 이미 처리하고 있어 코드 수정 불필요.
Changed Files
| 파일 | 변경 내용 | REQ |
|---|---|---|
README.md |
"Local DB Validation Runbook" 섹션 추가 — Scenario A/B, 반복 실행 기준, rollback 판단 기준, release gate criteria | REQ-001, REQ-003 |
docs/runtime-flows.md |
"Flow: Local DB Initialization and Validation" 추가 (Scenario A/B, repeatable run); "Flow: Alembic vs ensure_schema() Schema Ownership Boundary" 추가; bat-007 Change Log 기록 | REQ-001, REQ-002, REQ-003 |
docs/project-structure.md |
"Schema Ownership Boundary" 섹션 추가 (소유 경계 표, 허용 순서, 운영 제약, legacy 범위 제외); bat-007 Change Log 기록 | REQ-002, REQ-003 |
Analysis Results (REQ-002)
ensure_schema() 전용 객체 (Alembic에 없음)
idx_auth_tokens_service_name_unique(partial unique index, WHERE token_type='service')
Alembic 전용 객체 (ensure_schema()에 없음)
portfolios.market(revision 0014)auth_tokens.runtime_id+idx_auth_tokens_runtime_id_unique(revision 0014)broker_credentialstable (revision 0014)ledger_tradestable (revision 0014)
공유 객체 (양쪽 모두 관리)
- users, auth_tokens, strategy_sets, portfolios, portfolio_ledger, portfolio_comments, portfolio_tags + 대부분의 인덱스
- 모두 IF NOT EXISTS 또는 inspector guard로 보호됨
충돌 해결 메커니즘 확인
bootstrap_or_upgrade_to_head()(app/db/migrations.py): alembic_version 테이블 여부 → legacy 테이블 여부로 stamp 분기. 코드 확인 완료.- Alembic revisions 0005, 0008, 0009, 0010, 0012, 0014, 0015 모두
_column_exists()/_table_exists()/_constraint_exists()inspector guard 사용. 확인 완료.
Execution Log
app/repositories/postgres.pyensure_schema() 전체 분석 완료 — 생성 객체 18종 목록화migrations/versions/15개 revision 분석 완료 — 소유 경계 분류bootstrap_or_upgrade_to_head()로직 확인 — legacy stamp 경로 정상 동작 확인docker-compose.local-test.yml확인 — 검증 시나리오 실행 환경 충족 (TimescaleDB healthcheck 설정 완비)app/cli/commands/health.py확인 — init-db/migrate-db/health-check 출력 필드 고정 확인- README.md, docs/runtime-flows.md, docs/project-structure.md 갱신 완료
Validation
코드 변경 없음 → pytest 재실행 불필요. 문서 변경 only.
# 문서 변경 범위 확인
git diff --name-only
# 기대: README.md, docs/runtime-flows.md, docs/project-structure.md,
# docs/batches/bat-007_.../design.md, planning.md, implementation.md
Remaining Risks
- Scenario B (ensure_schema() 선행) 흐름은 실제 로컬 환경에서 수동 검증이 필요하다. 이 batch는 코드 분석 + 문서화 기반 evidence이며 실제 DB 기반 실행 검증은 release 전 수행 권장.
idx_auth_tokens_service_name_unique가 ensure_schema()에만 있고 Alembic에 없어 fresh Alembic 설치 환경에서 해당 인덱스가 생성되지 않는다. 기능 영향: service token name unique 보장 불완전. 후속 batch 검토 필요.