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

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

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