USE extremadesk;

SET @db := DATABASE();
SET @has_telefone := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'usuarios' AND COLUMN_NAME = 'telefone'
);
SET @stmt := IF(@has_telefone = 0,
    'ALTER TABLE usuarios ADD COLUMN telefone varchar(50) DEFAULT NULL AFTER email',
    'SELECT 1'
);
PREPARE s FROM @stmt;
EXECUTE s;
DEALLOCATE PREPARE s;
