USE bulo;

SET @col_categoria_veiculo := (
  SELECT COUNT(*)
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'corridas'
    AND COLUMN_NAME = 'categoria_veiculo'
);

SET @sql := IF(
  @col_categoria_veiculo = 0,
  'ALTER TABLE corridas ADD COLUMN categoria_veiculo ENUM(''economica'', ''plus'', ''pro'') NOT NULL DEFAULT ''economica'' AFTER valor',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
