SET @has_cantidad_col := (
    SELECT COUNT(*)
    FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = DATABASE()
      AND TABLE_NAME = 'producto_variantes'
      AND COLUMN_NAME = 'cantidad'
);

SET @sql := IF(
    @has_cantidad_col = 0,
    'ALTER TABLE producto_variantes ADD COLUMN cantidad INT UNSIGNED NOT NULL DEFAULT 0 AFTER sku',
    'SELECT 1'
);

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