-- 049: Add target_audience field to canonical_controls
-- Distinguishes who a control is relevant for: enterprises, authorities, providers, or all.
-- Safe: only runs if the table exists (may not exist on all environments)

DO $$
BEGIN
    IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'canonical_controls') THEN
        ALTER TABLE canonical_controls ADD COLUMN IF NOT EXISTS
            target_audience VARCHAR(20) DEFAULT NULL
            CHECK (target_audience IN ('enterprise', 'authority', 'provider', 'all'));
        CREATE INDEX IF NOT EXISTS idx_cc_target_audience ON canonical_controls(target_audience);
    END IF;
END $$;
