Last active
August 18, 2020 22:25
-
-
Save icelander/4b92bd1cd204b1e74e092827dcdde256 to your computer and use it in GitHub Desktop.
These queries help you find user memberships in the Mattermost database. Tested against schema version 5.24.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Gets all channel memberships for Open and Private channels | |
SELECT t.DisplayName as TeamName, | |
c.DisplayName as ChannelName, | |
c.Type, -- O is a public channel, P is a private channel | |
u.FirstName, | |
u.LastName, | |
u.Username, | |
u.Email, | |
IF (cm.LastViewedAt!=0, FROM_UNIXTIME((cm.LastViewedAt/1000)), 'Never') AS LastViewed | |
FROM ChannelMembers cm | |
JOIN Channels c ON cm.ChannelId = c.Id | |
JOIN Users u on cm.UserId = u.Id | |
JOIN Teams t ON c.TeamId = t.Id | |
WHERE | |
u.DeleteAt = 0 -- Only active users | |
AND t.Name = 'a-team' -- Filter by team | |
ORDER BY t.name, c.name; | |
-- Gets all team members | |
SELECT t.DisplayName as TeamName, | |
u.FirstName, | |
u.LastName, | |
u.Username, | |
u.Email, | |
tm.SchemeAdmin, | |
tm.SchemeGuest | |
FROM Teams t | |
JOIN TeamMembers tm ON tm.TeamId = t.Id | |
JOIN Users u ON tm.UserId = u.Id | |
WHERE | |
tm.DeleteAt = 0 | |
AND u.DeleteAt = 0 -- Only active users | |
AND t.Name = 'a-team' -- Filter by team | |
ORDER BY t.Name; | |
-- Gets all direct and group message channel memberships | |
SELECT c.DisplayName as ChannelName, -- Direct messages don't have a display name | |
c.Type, -- G is group message, D is direct message | |
u.FirstName, | |
u.LastName, | |
u.Username, | |
u.Email, | |
IF (cm.LastViewedAt!=0, FROM_UNIXTIME((cm.LastViewedAt/1000)), 'Never') AS LastViewed | |
FROM Channels c | |
JOIN ChannelMembers cm ON cm.ChannelId = c.Id | |
JOIN Users u on cm.UserId = u.Id | |
WHERE | |
c.Type IN ('G', 'D') | |
ORDER BY c.name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment