fix(portfolio): align corporate action schema definitions
This commit is contained in:
@@ -22,6 +22,10 @@ def upgrade() -> None:
|
|||||||
profit_buffer NUMERIC(20,8) NOT NULL, ledger_entry_id BIGINT,
|
profit_buffer NUMERIC(20,8) NOT NULL, ledger_entry_id BIGINT,
|
||||||
UNIQUE (portfolio_id, idempotency_key)
|
UNIQUE (portfolio_id, idempotency_key)
|
||||||
)"""))
|
)"""))
|
||||||
|
op.get_bind().execute(text(
|
||||||
|
"CREATE INDEX IF NOT EXISTS idx_corporate_actions_portfolio "
|
||||||
|
"ON portfolio_corporate_actions (portfolio_id, effective_date)"
|
||||||
|
))
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
op.get_bind().execute(text("DROP TABLE IF EXISTS portfolio_corporate_actions"))
|
op.get_bind().execute(text("DROP TABLE IF EXISTS portfolio_corporate_actions"))
|
||||||
|
|||||||
@@ -336,16 +336,25 @@ class PostgresPortfolioRepository:
|
|||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS portfolio_corporate_actions (
|
CREATE TABLE IF NOT EXISTS portfolio_corporate_actions (
|
||||||
corporate_action_id UUID PRIMARY KEY, portfolio_id TEXT NOT NULL,
|
corporate_action_id UUID PRIMARY KEY,
|
||||||
asset_id UUID, action_type TEXT NOT NULL, effective_date DATE NOT NULL,
|
portfolio_id TEXT NOT NULL REFERENCES portfolios(portfolio_id) ON DELETE RESTRICT,
|
||||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), actor_user_id TEXT,
|
asset_id UUID NOT NULL REFERENCES assets(asset_id) ON DELETE RESTRICT,
|
||||||
evidence_ref TEXT NOT NULL, idempotency_key TEXT NOT NULL,
|
action_type TEXT NOT NULL CHECK (action_type = 'stock_consolidation'),
|
||||||
payload_hash TEXT NOT NULL, quantity_before NUMERIC(20,8) NOT NULL,
|
effective_date DATE NOT NULL,
|
||||||
quantity_after NUMERIC(20,8) NOT NULL, average_price_before NUMERIC(20,8) NOT NULL,
|
recorded_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
average_price_after NUMERIC(20,8) NOT NULL, total_cost_basis NUMERIC(20,8) NOT NULL,
|
actor_user_id TEXT,
|
||||||
cash_balance NUMERIC(20,8) NOT NULL, profit_buffer NUMERIC(20,8) NOT NULL,
|
evidence_ref TEXT NOT NULL,
|
||||||
ledger_entry_id BIGINT NOT NULL,
|
idempotency_key TEXT NOT NULL,
|
||||||
UNIQUE(portfolio_id, idempotency_key)
|
payload_hash TEXT NOT NULL,
|
||||||
|
quantity_before NUMERIC(20,8) NOT NULL,
|
||||||
|
quantity_after NUMERIC(20,8) NOT NULL,
|
||||||
|
average_price_before NUMERIC(20,8) NOT NULL,
|
||||||
|
average_price_after NUMERIC(20,8) NOT NULL,
|
||||||
|
total_cost_basis NUMERIC(20,8) NOT NULL,
|
||||||
|
cash_balance NUMERIC(20,8) NOT NULL,
|
||||||
|
profit_buffer NUMERIC(20,8) NOT NULL,
|
||||||
|
ledger_entry_id BIGINT,
|
||||||
|
UNIQUE (portfolio_id, idempotency_key)
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user