ALTER TABLE op_fault_detection_rules
    ADD COLUMN pattern_title VARCHAR(255) NOT NULL DEFAULT '' AFTER id,
    ADD COLUMN criticality ENUM('low', 'medium', 'high') NOT NULL DEFAULT 'medium' AFTER explanation,
    ADD COLUMN is_active TINYINT(1) NOT NULL DEFAULT 1 AFTER criticality;

UPDATE op_fault_detection_rules
SET pattern_title = CASE
        WHEN pattern_title IS NULL OR pattern_title = '' THEN pattern
        ELSE pattern_title
    END,
    criticality = COALESCE(criticality, 'medium'),
    is_active = COALESCE(is_active, 1);
