Export and delete Town Square channel history

Dear Community!

I want to migrate the Town Square channel history into another (Private) channel and then delete the whole history from Town Square.
Is this somehow possible? I have seen that there is no straight command for this in the Mattermost CLI tool, but maybe somehow, like modifying the database, it would be possible.

Thanks for your help in advance!

Hi, @radokristof

I don’t see any easy way of doing this but I have asked the team to see if it is possible. As Town Square is meant to be public channel in general, is there any specific reason on moving the conversation there into the private channel and deleting the history from the origin?

The only reason I want this, is because I have to invite new members to the Team and there are a lot of conversation in the Town Square channel which I don’t want them to see.


Same issue. It would be extremely useful.

Hello, @radokristof @kenshin79

You are welcome. I have opened up a discussion in the Ask R&D channel here if you would like to join the conversation. Since Town Square is a standard channel for a team, this will be the tricky part according to the engineer that I am in touch with.

1 Like

@ahmaddanial do you think a SQL copy-and-move function would be a way to accomplish this? A perse relabel of the channel the messages belong to?

My thought is something along the lines of creating the new private channel, and then replacing the channel ID of the messages we want to move with that of the private channel we just created.

I’m genuinely not sure how viable that would be as a solution but it could be a bridge until a plugin or something like that can be developed, if this idea would actually work at all.


While I won’t say that it is not possible, it is tricky because direct SQL updates to the database can potentially cause database corruption and data inconsistency.

If we are to move towards that direction, it has to be tested on a staging environment and do it on a single post first since we are manipulating the data.

I attempted this on my end. I pulled the data of the posts that I want to move from the Mattermost team’s Town Square (for example).

SELECT c.Id, u.Username, c.Name, t.Name, p.Message FROM Users AS u LEFT JOIN Posts AS p ON u.Id = p.UserId LEFT JOIN Channels AS c ON c.Id = p.ChannelId LEFT JOIN Teams AS t ON c.TeamId = t.Id WHERE c.Name = "town-square" AND t.Name = "<team_name>";

After that, I ran the UPDATE statement to move the posts from Town Square to the new channel completely:

UPDATE Posts SET ChannelId = "<original_town_square_id>" WHERE ChannelId = "<new_channel_id>";

After clearing the cache of the client, the posts in the town-square is gone and it is moved to the new one. While it may have worked, my concern is just the potential long term effect of this.

Another option that you can look at is the wrangler plugin - GitHub - gabrieljackson/mattermost-plugin-wrangler: Manage Mattermost Messages Masterfully!


I do understand the risk, I was thinking of it more like a last-ditch for someone who really wanted to move the messages, and was willing to accept the risk. Is it correct to presume that the reason that a feature like this hasn’t been worked on is due to the difficulties of programmatically writing the same function in Go, that is compatible with the current codebase? Or is there something else that limits the development of a coded solution to this issue? I just am seeking to better understand the constraints to the problem, so I can provide more useful input :slight_smile:

Hi, @XxLilBoPeepsxX

In terms of the difficulty or limitation, I cannot say for sure. For transparency purposes, it would be best for us to bring this up in the public Uservoice platform where the dev/engineering team keeps an eye on potential features.

@radokristof @kenshin79 Would any of you be open to create a new topic there? Happy to do it on your behalf if you prefer.

1 Like

definitly working! you saved my day :wink:

We tested the direct update of ChannelId in the Posts table, and this seems to work like a charm, without any side-effect. I was concerned about the search feature because I was afraid it was using some external indexes, but searching messages that have been moved is still working.