Skip to content

Commit 2878c21

Browse files
committed
add the group_members_expanded db view
1 parent 5fcc218 commit 2878c21

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP VIEW group_members_expanded;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE VIEW
2+
group_members_expanded
3+
AS
4+
WITH all_members AS (
5+
SELECT user_id, group_id FROM group_members
6+
UNION
7+
SELECT user_id, organization_id AS group_id FROM organization_members
8+
)
9+
SELECT
10+
users.id AS user_id,
11+
users.username,
12+
users.avatar_url AS user_avatar_url,
13+
groups.organization_id AS organization_id,
14+
groups.name AS group_name,
15+
all_members.group_id AS group_id
16+
FROM
17+
all_members
18+
JOIN
19+
users ON users.id = all_members.user_id
20+
JOIN
21+
groups ON groups.id = all_members.group_id
22+
WHERE
23+
users.deleted = 'false';
24+
25+
COMMENT ON VIEW group_members_expanded IS 'Joins group members with user information, organization ID, group name. Includes both regular group members and organization members (as part of the "Everyone" group).';

0 commit comments

Comments
 (0)