How to merge channels or move messages?

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 Move a message to another channel – Mattermost Feature Proposal Forum). 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

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.

2 Likes

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

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 : )

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

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.

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

Hello,

Thank you for your post @jwilander, as old as it is, it stills works in 5.11.0., and it served me well.

I would also like to point that the last point (number 5) command should be DELETE FROM Channels WHERE Id = 'oldId'; because Id is the right column in the table Channels, not ChannelId.

4 years later, any news? Can someone confirm that this is still a valid approach?

Does this work across teams by any chance?

Answering my own question, just found this:

Mattermost v4.2 and later supports an admin CLI command to move channels between teams.

More information in our docs: Redirect

Hi all,
Could anyone please share if history messages are kept when moving a channel to another team?
Thank you!

Hi Anna! At this time, I don’t believe Mattermost supports transferring message history when moving a channel between teams, but you can explore our export channel data documentation for potential alternatives. Let us know if there’s anything else we can assist with!

1 Like