-- Migration 027: Kontext-Bindings – Fokus + Trainingsstil ohne Stilrichtung (z. B. Karate + Breitensport)
-- Ersetzt die alte CHECK-Constraint-Kette; partielle Unique-Indizes für alle vier Kombinationen.
-- Datum: 2026-04-27

ALTER TABLE maturity_model_context_bindings DROP CONSTRAINT IF EXISTS chk_mcb_tier;

DROP INDEX IF EXISTS uq_mmcb_focus_style_ttype;

-- Fokus + Stilrichtung + Trainingsstil (alle drei gesetzt)
CREATE UNIQUE INDEX IF NOT EXISTS uq_mmcb_focus_style_training
    ON maturity_model_context_bindings (focus_area_id, style_direction_id, training_type_id)
    WHERE style_direction_id IS NOT NULL AND training_type_id IS NOT NULL;

-- Fokus + Trainingsstil (ohne Stilrichtung)
CREATE UNIQUE INDEX IF NOT EXISTS uq_mmcb_focus_training
    ON maturity_model_context_bindings (focus_area_id, training_type_id)
    WHERE style_direction_id IS NULL AND training_type_id IS NOT NULL;
