-- CostusWorx © 2026 — retireuk.costusworx.co.za
-- Segment-allocation columns for the simulation engine. Complements fund_alloc.sql.
-- Idempotent (ADD COLUMN IF NOT EXISTS), so safe to run whether or not fund_alloc.sql
-- has already been applied.
--
-- Percentages (60.00 = 60%), matching fund_alloc.sql. The simulation reads these
-- five segment weights and drives returns from each segment's index series; a fund
-- needs only its WEIGHTS here, not its own return history.
--   alloc_equity_local → UK equity (FTSE All-Share)   alloc_cash     → cash (SONIA)
--   alloc_equity_intl  → offshore equity (MSCI World GBP)   alloc_property → UK listed/direct property
--   alloc_bonds        → UK gilts
SET NAMES utf8mb4;

ALTER TABLE funds
    -- Base four already added by fund_alloc.sql; repeated here with IF NOT EXISTS
    -- so this migration is self-sufficient. Existing definitions win if present.
    ADD COLUMN IF NOT EXISTS alloc_equity_local DECIMAL(5,2) DEFAULT NULL COMMENT 'UK Equities %',
    ADD COLUMN IF NOT EXISTS alloc_equity_intl  DECIMAL(5,2) DEFAULT NULL COMMENT 'International Equities %',
    ADD COLUMN IF NOT EXISTS alloc_bonds        DECIMAL(5,2) DEFAULT NULL COMMENT 'Bonds %',
    ADD COLUMN IF NOT EXISTS alloc_cash         DECIMAL(5,2) DEFAULT NULL COMMENT 'Cash / Money Market %',
    -- New: the missing 5th segment + provenance markers
    ADD COLUMN IF NOT EXISTS alloc_property     DECIMAL(5,2) DEFAULT NULL COMMENT 'UK/Global Listed Property %',
    ADD COLUMN IF NOT EXISTS alloc_source       VARCHAR(20)  DEFAULT NULL COMMENT 'ia_default|benchmark|default|mdd|manual',
    ADD COLUMN IF NOT EXISTS alloc_asof         DATE         DEFAULT NULL COMMENT 'As-of date of the stored allocation';
