BEGIN;

-- candles.timestamp: TEXT ISO-string → TIMESTAMPTZ
ALTER TABLE candles
    ALTER COLUMN "timestamp" TYPE TIMESTAMPTZ
    USING "timestamp"::TIMESTAMPTZ;

-- retrain_requests.requested_at: TEXT ISO-string → TIMESTAMPTZ
ALTER TABLE retrain_requests
    ALTER COLUMN requested_at TYPE TIMESTAMPTZ
    USING requested_at::TIMESTAMPTZ;

-- paper_portfolio.starting_balance: TEXT decimal-string → NUMERIC
ALTER TABLE paper_portfolio
    ALTER COLUMN starting_balance TYPE NUMERIC
    USING starting_balance::NUMERIC;

-- paper_portfolio.current_cash: TEXT decimal-string → NUMERIC
ALTER TABLE paper_portfolio
    ALTER COLUMN current_cash TYPE NUMERIC
    USING current_cash::NUMERIC;

INSERT INTO schema_versions (version, description)
VALUES (13, 'fix TEXT column types: candles.timestamp, retrain_requests.requested_at, paper_portfolio balances')
ON CONFLICT DO NOTHING;

COMMIT;
