Files
team/server/channels/db/migrations/postgres/000157_backfill_roles_schemeid.up.sql
David KrauserandGitHub 89852b2a57 [MM-67741] Scope role_updated WS events to affected team/channel (#35497)
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.
2026-03-16 14:36:55 -04:00

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;