-- sql/migrations/staging/006_http_status_enum.sql
-- HTTP status now lives on the same ok/fail axis as SSL/DNS/WHOIS rather
-- than carrying a raw status code. The customer page shows a one-word
-- indicator, and we let HAProxy backend monitoring (whp-monitor-poll.py)
-- handle the per-minute "is it down" detection.

ALTER TABLE whp.ai_monitor_subscriptions
    ADD COLUMN IF NOT EXISTS http_status
        ENUM('ok','fail','unreachable','unknown')
        NOT NULL DEFAULT 'unknown'
        COMMENT 'Last HTTP probe outcome (set by scheduled-site-checks.php).';

-- The status code column is no longer used; drop it if still present.
SET @c := (SELECT COUNT(*) FROM information_schema.COLUMNS
           WHERE TABLE_SCHEMA = 'whp'
             AND TABLE_NAME   = 'ai_monitor_subscriptions'
             AND COLUMN_NAME  = 'http_status_code');
SET @s := IF(@c > 0,
             'ALTER TABLE whp.ai_monitor_subscriptions DROP COLUMN http_status_code',
             'SELECT 1');
PREPARE stmt FROM @s; EXECUTE stmt; DEALLOCATE PREPARE stmt;
