USE extremadesk;

SET @db := DATABASE();

SET @has_anexo := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'mensagens_chamado' AND COLUMN_NAME = 'anexo'
);
SET @stmt := IF(@has_anexo = 0,
    'ALTER TABLE mensagens_chamado ADD COLUMN anexo varchar(255) DEFAULT NULL AFTER mensagem',
    'SELECT 1'
);
PREPARE s FROM @stmt;
EXECUTE s;
DEALLOCATE PREPARE s;

SET @has_anexo_nome := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'mensagens_chamado' AND COLUMN_NAME = 'anexo_nome'
);
SET @stmt := IF(@has_anexo_nome = 0,
    'ALTER TABLE mensagens_chamado ADD COLUMN anexo_nome varchar(255) DEFAULT NULL AFTER anexo',
    'SELECT 1'
);
PREPARE s FROM @stmt;
EXECUTE s;
DEALLOCATE PREPARE s;
