USE bulo;

SET @col_disp := (
  SELECT COUNT(*)
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'usuarios'
    AND COLUMN_NAME = 'disponivel'
);

SET @sql := IF(
  @col_disp = 0,
  'ALTER TABLE usuarios ADD COLUMN disponivel ENUM(''sim'',''nao'') NOT NULL DEFAULT ''nao'' AFTER observacao_verificacao',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

UPDATE usuarios
SET disponivel = 'nao'
WHERE tipo = 'motorista' AND disponivel IS NULL;
