feat: refactor portfolio strategy references
This commit is contained in:
+14
-4
@@ -5,10 +5,11 @@
|
||||
This document defines the database schema in an AI-agent-friendly format.
|
||||
|
||||
- Source of truth: Alembic revisions in `migrations/versions`
|
||||
- Current baseline revision: `20260403_0002`
|
||||
- Current baseline revision: `20260403_0003`
|
||||
- Baseline files:
|
||||
- `migrations/versions/20260403_0001_initial_portfolio_schema.py`
|
||||
- `migrations/versions/20260403_0002_strategy_set_columns.py`
|
||||
- `migrations/versions/20260403_0003_portfolio_strategy_refs.py`
|
||||
|
||||
## 2. Scope
|
||||
|
||||
@@ -57,6 +58,10 @@ Purpose:
|
||||
|
||||
- Stores current portfolio state and strategy linkage.
|
||||
|
||||
Current baseline note:
|
||||
|
||||
- The columns below describe the currently migrated schema through revision `20260403_0003`.
|
||||
|
||||
Columns:
|
||||
|
||||
| Column | Type | Null | Default | Constraints / Notes |
|
||||
@@ -65,13 +70,12 @@ Columns:
|
||||
| broker | Text | NO | "kis" | Broker code |
|
||||
| status | Text | NO | "enabled" | Portfolio status |
|
||||
| symbol | Text | NO | - | Trading symbol |
|
||||
| strategy_name | Text | NO | "" | Strategy label |
|
||||
| strategy_params | JSONB | NO | '{}'::jsonb | Strategy parameters |
|
||||
| cash_balance | Float | NO | - | Current cash balance |
|
||||
| asset_quantity | Float | NO | - | Current asset quantity |
|
||||
| asset_price | Float | NO | 0 | Current price snapshot |
|
||||
| profit_buffer | Float | NO | 0 | Profit buffer amount |
|
||||
| current_strategy_set_id | Text | YES | - | Logical reference to `strategy_sets.id` (no FK) |
|
||||
| active_strategy_id | Text | YES | - | Logical reference to `strategy_sets.id` |
|
||||
| avabile_strategies | Text[] | YES | - | Nullable array of `strategy_sets.id` values |
|
||||
| created_at | DateTime(timezone=True) | NO | NOW() | Creation timestamp |
|
||||
| updated_at | DateTime(timezone=True) | NO | NOW() | Last update timestamp |
|
||||
| last_trade_at | DateTime(timezone=True) | YES | - | Last trade time |
|
||||
@@ -81,6 +85,11 @@ Constraints:
|
||||
- Primary key: `portfolio_id`
|
||||
- Foreign key constraints: none in baseline
|
||||
|
||||
Constraint notes:
|
||||
|
||||
- `active_strategy_id` is a nullable logical reference to `strategy_sets.id`
|
||||
- `avabile_strategies` stores zero or more selectable strategy set IDs when present
|
||||
|
||||
### 4.3 portfolio_ledger
|
||||
|
||||
Purpose:
|
||||
@@ -160,3 +169,4 @@ When schema changes:
|
||||
|---|---|---|
|
||||
| 20260403_0001 | migrations/versions/20260403_0001_initial_portfolio_schema.py | Initial schema for strategy sets, portfolios, ledger, indexes, optional hypertable |
|
||||
| 20260403_0002 | migrations/versions/20260403_0002_strategy_set_columns.py | Rename `strategy_name`->`name`, `strategy_config`->`config`, add unique `nick` |
|
||||
| 20260403_0003 | migrations/versions/20260403_0003_portfolio_strategy_refs.py | Remove embedded portfolio strategy fields, add `active_strategy_id` and `avabile_strategies` |
|
||||
|
||||
Reference in New Issue
Block a user