-- Script de migración para agregar el campo popular a la tabla planes
-- Ejecutar este script si la tabla planes ya existe sin el campo popular

-- Verificar si la columna popular existe antes de agregarla
SET @col_exists = (
  SELECT COUNT(*) 
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE TABLE_SCHEMA = DATABASE() 
    AND TABLE_NAME = 'planes' 
    AND COLUMN_NAME = 'popular'
);

SET @sql = IF(@col_exists = 0,
  'ALTER TABLE planes ADD COLUMN popular TINYINT(1) NOT NULL DEFAULT 0 COMMENT ''Indica si el plan es popular/recomendado'' AFTER features',
  'SELECT ''La columna popular ya existe'' AS message'
);

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- Actualizar el plan Desktop Windows como popular
UPDATE planes
SET popular = 1
WHERE codigo = 'DESKTOP';

-- Asegurar que los otros planes no sean populares
UPDATE planes
SET popular = 0
WHERE codigo != 'DESKTOP' OR codigo IS NULL;

