USE whp;

-- =====================================================================
-- Site Traffic Analytics: branch ai_monitor_log_reviews on review_type
-- =====================================================================
-- Adds a review_type column so the existing review worker can fan out
-- between the existing 'log' flow and the new 'traffic' flow.
--
-- Idempotent: guarded with INFORMATION_SCHEMA so re-running the migration
-- is safe.
-- =====================================================================

SET @col_exists := (
  SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA='whp' AND TABLE_NAME='ai_monitor_log_reviews' AND COLUMN_NAME='review_type'
);
SET @sql := IF(@col_exists = 0,
  "ALTER TABLE whp.ai_monitor_log_reviews ADD COLUMN review_type ENUM('log','traffic') NOT NULL DEFAULT 'log' AFTER id",
  "SELECT 'review_type column already exists' AS msg"
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
