-- Pipeline funnel v2 — collapse the inherited 6-stage opportunity funnel into the locked
-- 4-stage per-investor funnel: lead -> engaged -> diligence -> commitment, terminal at
-- commitment. See ROADMAP "Pipeline stages + investor flags/labels -- LOCKED SPEC" (2026-06-19)
-- and server.PIPELINE_STAGES.
--
-- DATA-ONLY + DEPLOYMENT-STATE-INVARIANT (migrations guide): targets stage values
-- structurally, so it is a no-op on a fresh DB (no opportunities) and remaps deterministically
-- on a populated one.
--   outreach, meeting   -> engaged      (a two-way conversation has begun; "meeting" was an
--                                         activity, not a position, so it folds in here)
--   due_diligence       -> diligence
--   committed, funded   -> commitment   (terminal; post-commit $ lives in the grid fund cell,
--                                         and fund admin owns post-commitment -- no "funded" stage)
UPDATE opportunities SET stage = 'engaged'    WHERE stage IN ('outreach', 'meeting');
UPDATE opportunities SET stage = 'diligence'  WHERE stage = 'due_diligence';
UPDATE opportunities SET stage = 'commitment' WHERE stage IN ('committed', 'funded');

-- The stray legacy 'lost' value is not in the new settable enum, and a lost deal is a dead
-- deal: ARCHIVE (soft-delete) the opportunity rather than leave an un-settable stage on a live
-- row. The grid investor row is left fully intact (the grid is canonical); graveyarding the
-- investor stays a human action, never an auto-mutation (human-in-the-loop guardrail). The
-- stage text is left as 'lost' on the archived row for provenance -- it is filtered out
-- everywhere by deleted_at IS NULL.
UPDATE opportunities SET deleted_at = datetime('now'), updated_at = datetime('now')
    WHERE stage = 'lost' AND deleted_at IS NULL;
