feat: apply rel-001 feedback cleanup

This commit is contained in:
2026-06-05 13:57:46 +09:00
parent 84de34c301
commit 2470c0a00c
28 changed files with 992 additions and 32 deletions
@@ -0,0 +1,53 @@
"""Rename ledger_trades.asset_id to portfolio_id for column-name semantic alignment (REQ-033)
Revision ID: 20260601_0024
Revises: 20260521_0023
Create Date: 2026-06-01 00:00:00
Background:
- REQ-029 implementation stored `portfolio_id` values in the `asset_id` column of `ledger_trades`,
causing schema readers to misinterpret the column as an `assets.asset_id` reference.
- dcy-005 FR-1 + REQ-033 mandates renaming the column to align name and meaning.
- No backfill required: existing values are already `portfolio_id` semantics.
"""
from __future__ import annotations
from alembic import op
from sqlalchemy import inspect, text
revision = "20260601_0024"
down_revision = "20260521_0023"
branch_labels = None
depends_on = None
def _column_exists(inspector, table_name: str, column_name: str) -> bool:
cols = inspector.get_columns(table_name)
return any(c["name"] == column_name for c in cols)
def upgrade() -> None:
bind = op.get_bind()
inspector = inspect(bind)
if not inspector.has_table("ledger_trades"):
return
if _column_exists(inspector, "ledger_trades", "asset_id") and not _column_exists(
inspector, "ledger_trades", "portfolio_id"
):
op.execute(text("ALTER TABLE ledger_trades RENAME COLUMN asset_id TO portfolio_id"))
def downgrade() -> None:
bind = op.get_bind()
inspector = inspect(bind)
if not inspector.has_table("ledger_trades"):
return
if _column_exists(inspector, "ledger_trades", "portfolio_id") and not _column_exists(
inspector, "ledger_trades", "asset_id"
):
op.execute(text("ALTER TABLE ledger_trades RENAME COLUMN portfolio_id TO asset_id"))