Mattermost Peer-to-Peer Forum

How to merge channels or move messages?

#1

After some month of experience using Mattermost - which we actually like - we would like to reorganize and simplify the channels we use. Unfortunately I didn’t find a way to merge channels or move messages to another channel (I found that feature request https://mattermost.uservoice.com/forums/306457-general/suggestions/11080068-move-a-message-to-another-channel). So currently there seems to be no built-in way of doing this, unfortunately.

Is there a hacky way of moving messages or merging channels?

Thanks for any hints!

2 Likes
General Queries for using Mattermost
#2

Hi @FreeMinded,

There’s no easy way to do this right now but it should be possible with some database manipulation. We recommend against modifying the database directly since it can have unintentional side effects that break your system. That said, I can point you in the right direction and I strongly recommend backing up your database before making any manual changes to it.

So I haven’t tried this myself, but in theory you should be able to:

  1. SELECT Id FROM Channels WHERE Name = 'channel-to-keep'; - save this Id and I’ll refer to it as finalId
  2. SELECT Id FROM Channels WHERE Name = 'channel-to-be-merged'; - save this Id and I’ll refer to it as oldId
  3. UPDATE Posts SET ChannelId = 'finalId' WHERE ChannelId = 'oldId'; - this will move all the posts over
  4. DELETE FROM ChannelMembers WHERE ChannelId = 'oldId'; - this will remove any old channel member objects for the old channel and users from the old channel will need to manually join the final channel if they weren’t already in it
  5. DELETE FROM Channels WHERE ChannelId = 'oldId'; - this will remove the old channel

You will also need to update or delete the old channel Id in additional tables if you have IncomingWebhooks, OutgoingWebhooks, or Commands on that channel.

Note those queries are given in MySQL syntax and might be slightly different for PostgreSQL.

1 Like
#3

Hi @jwilander
Thanks! Will try it out in calm moment. I’ll let you know about the outcome.

#4

Hello @jwilander,

Considering this is quite an old post, I was wondering if there is now an administrative tool to do this or if this is still the best way.

Thank you,

tarek : )

#5

Hi @Tarek,

Thank you for your question,

At the moment, there isn’t a way to merge channels or move messages. The method jwilander laid out above is still the best way.

1 Like
#6

Manually changing the channel ID on posts in the database like this procedure is still the only way I could find to move messages between channels, but for the record it does work in Mattermost 5.1.

I did have some trouble getting some sort of caching out of the way, even after a restart and cold-flushing client browsers it still quite stubbornly held on to serving cached material. I found manually updating one of the edited time stamp of a post before the earliest moved message (in both rooms) to a current time triggered some kind of a reload and the channel display updated.

#7

Now it is 2019. Any progress since 2016? How long does it take to paste 5 SQL statements into Go code?