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?
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:
SELECT Id FROM Channels WHERE Name = 'channel-to-keep'; - save this Id and I’ll refer to it as finalId
SELECT Id FROM Channels WHERE Name = 'channel-to-be-merged'; - save this Id and I’ll refer to it as oldId
UPDATE Posts SET ChannelId = 'finalId' WHERE ChannelId = 'oldId'; - this will move all the posts over
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
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.
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.
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.
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!