-- Phase 1 / Migration 5
-- Repair or seed rm_model_config for rm_2.0 with approved Phase 1 weights.
-- Canonical runtime flags remain env-only per approved plan.
-- No DB feature-flag rows are created in this migration.
-- Pre-check:
-- SELECT model_version, is_active, config_json::text
-- FROM rm_model_config WHERE model_version = 'rm_2.0';
-- Post-check:
-- SELECT model_version, is_active, config_json->'nba' AS nba_weights,
--        config_json->'mlb' AS mlb_weights,
--        config_json->>'composite_version' AS composite_version
-- FROM rm_model_config WHERE model_version = 'rm_2.0';
-- Rollback:
-- UPDATE rm_model_config
-- SET config_json = '{"signals": ["grok", "piff", "digimon", "dvp"], "weights": {"nba": {"grok": 0.35, "piff": 0.35, "digimon": 0.30}, "default": {"grok": 0.50, "piff": 0.50, "digimon": 0.00}}, "datasets": ["rm_forecast_cache_v2", "rm_forecast_accuracy_v2", "DailyPick"], "read_only": false, "composite_version": "v1"}'::jsonb,
--     is_active = true
-- WHERE model_version = 'rm_2.0';

INSERT INTO rm_model_config (model_version, config_json, is_active)
VALUES (
  'rm_2.0',
  '{
    "nba": {"grok": 0.30, "piff": 0.30, "digimon": 0.25, "dvp": 0.08, "rag": 0.07},
    "nhl": {"grok": 0.40, "piff": 0.35, "dvp": 0.10, "rag": 0.15},
    "mlb": {"grok": 0.20, "mlb_matchup": 0.25, "mlb_phase": 0.25, "fangraphs": 0.15, "piff": 0.05, "dvp": 0.05, "rag": 0.05},
    "ncaab": {"grok": 0.55, "kenpom": 0.45},
    "soccer": {"grok": 0.40, "piff": 0.40, "corner_scout": 0.20},
    "composite_version": "rm_2.0"
  }'::jsonb,
  true
)
ON CONFLICT (model_version) DO UPDATE
SET config_json = EXCLUDED.config_json,
    is_active = EXCLUDED.is_active;
