[SOLVED] How can I delete teams?

I ended up creating three teams when trying to configure Mattermost, and I’d like to remove two of them.

By the way, apparently you can’t have the word “web” in your team’s URL. I wanted it to be /weblinx/, the name of my company, but it just generated /linx/.

1 Like

Hi @revxx14,

Thanks for the feedback!

To maintain full auditing teams cannot be deleted in Beta1. We have a feature to deactivate teams in a future release.

You’re hitting a reserved word list in team creation, which was intended for public instances, but this really isn’t necessary if you’re hosting on-prem, so there’s a ticket tracking making this a config option now.

Highly appreciate your feedback, we’ll queue these to get knocked out.

Is it possible to delete teams manually?

I am using the mattermost bundled with gitlab and also would like to delete some accidental created teams.

Maybe it’s as easy as delete some records from a DB? Which DB and how to do?

Thanks in advance…

mablae

Hi @mablae,

It is possible to manually manipulate the database to remove a team and I’ll show you how below. First though, a warning that any database manipulation is NOT recommended, especially if you have critical data you don’t want to lose.

That said if you’re using MySQL you can remove a team by doing the following:

  1. Login to MySQL with mysql --host=dockerhost --user=mmuser --password=mostest
    i. This might be mysql --host=localhost --user=mmuser --password=mostest if you’re running release bits.
  2. Select the database with use mattermost_test;
    i. The database name might also be mattermost or mattermost_production
  3. Find the team Id with SELECT Id FROM Teams WHERE Name = 'someteamname'; and copy it
  4. Delete the team with DELETE FROM Teams WHERE Id = 'yourteamid';
  5. Delete the users with DELETE FROM Users WHERE TeamId = 'yourteamid';
  6. Delete the sessions with DELETE FROM Sessions WHERE TeamId = 'yourteamid';
  7. (Optional) Delete the channels with DELETE FROM Channels WHERE TeamId = 'yourteamid';
  8. Restart your server to clear the sessions cache.

Doing this might have unintended side effects, so it’s up to you whether or not to do it. The steps for Postgres should be very similar.

Just to add there is now a command line tool for administration that includes the ability to delete teams.

1 Like

Speaking of the command line tool, it wasn’t working for me last week… Details are in my Slack import failure thread, but can someone supply a working example command line to delete a team?

Update: for others who end up here looking for help, we resolved my problem in my other thread. TL;DR when the command line tool asks questions, respond with YES in all caps.

Thanks!

I see this link is not working.
Is there an alternative?

Here you go http://docs.mattermost.com/administration/command-line-tools.html

1 Like

I read the cli docu linked above but its not working for me:

root@254daecba851:/mattermost/bin#sudo ./platform team delete AMS
Have you performed a database backup? (YES/NO):
YES
Are you sure you want to delete the teams specified?  All data will be permanently deleted? (YES/NO):
YES
Unable to find team 'AMS'
root@254daecba851:/mattermost/bin#

I also tried sudo ./platform team delete “AMS” and its not working either, same error. I do see the team though in my System Console.

Any thoughts?

On mattermost when you go to team settings > General Settings > Team Name, try to copy the name exactly as is and use it, if there is spacing put it inside quotes, like " name here" and see if that works…

Additionally you could try pointing your config file on the command line like -c path_to_your/config.json

Tried that, no luck:

root@254daecba851:/mattermost/bin# ./platform team delete "AMS" -c /mattermost/config/config.json
Have you performed a database backup? (YES/NO):
YES
Are you sure you want to delete the teams specified?  All data will be permanently deleted? (YES/NO):
YES
Unable to find team 'AMS'
root@254daecba851:/mattermost/bin# 

Also tried “AMS” but got the same result.

I looked in the database for my instance of Mattermost 3.7.2 and noticed that the Team database holds two versions of the team name. One is the DisplayName, and the other is Name. I experimented a little and found that the command doesn’t work when you use DisplayName. You have to use Name.

The Name is created from the DisplayName by replacing spaces with dashes and converting to lowercase. So if your team name is AMS, then its name in the database is ams.

Try this to see if it works:

sudo ./platform team delete ams

@JeffSchering sorry I missed your reply but your solution did work indeed. Thanks!