mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
With this change, we now scope role_updated websocket events to users that need to receive them. Built-in and unowned role broadcast globally, team-scheme roles emit one event per team using the role, channel-scheme roles emit one event per channel using the role. To efficiently find a role's owning scheme, a schemeid column is added to the roles table. The ID is set when the scheme creates its related roles.
24 lines
701 B
SQL
24 lines
701 B
SQL
UPDATE roles
|
|
SET schemeid = match.scheme_id
|
|
FROM (
|
|
SELECT DISTINCT ON (role_name) id AS scheme_id, role_name
|
|
FROM (
|
|
SELECT id, unnest(ARRAY[
|
|
defaultteamadminrole,
|
|
defaultteamuserrole,
|
|
defaultteamguestrole,
|
|
defaultchanneladminrole,
|
|
defaultchanneluserrole,
|
|
defaultchannelguestrole,
|
|
defaultplaybookadminrole,
|
|
defaultplaybookmemberrole,
|
|
defaultrunadminrole,
|
|
defaultrunmemberrole
|
|
]) AS role_name
|
|
FROM schemes
|
|
) expanded
|
|
WHERE role_name IS NOT NULL AND role_name <> ''
|
|
ORDER BY role_name, scheme_id
|
|
) match
|
|
WHERE roles.name = match.role_name;
|