USE bulo;

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

SET @sql := IF(
  @col_forma_pagamento = 0,
  'ALTER TABLE corridas ADD COLUMN forma_pagamento ENUM(''dinheiro'', ''online'') NOT NULL DEFAULT ''dinheiro'' AFTER valor',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
