-- Add analysis result columns to backtest_results for summary metrics and equity
-- curve. Existing databases already at version 1 receive these columns here.
-- Backfill defaults keep the NOT NULL constraint valid for existing rows, then the
-- defaults are dropped so application code stays the single source of values.
ALTER TABLE backtest_results
    ADD COLUMN IF NOT EXISTS total_return NUMERIC NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS trade_count INTEGER NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS equity_curve JSONB NOT NULL DEFAULT '[]'::jsonb;

ALTER TABLE backtest_results
    ALTER COLUMN total_return DROP DEFAULT,
    ALTER COLUMN trade_count DROP DEFAULT,
    ALTER COLUMN equity_curve DROP DEFAULT;
