USE extremadesk;

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