Update all Slack installations for workspace
What does this MR do and why?
Due to our modelling (mentioned in
&9418 (closed)) we create a
SlackIntegration
record per GitLab for Slack app integration that is created.
The information in SlackIntegration
records that share a team_id
(a Slack workspace ID) should always be the same, and we should more correctly only create
a single SlackIntegration
record per Slack workspace.
Since the information in these records should always been the same, we
currently paper-over this modelling problem by mass-updating all
records that share a team_id
(Slack workspace ID) whenever another SlackIntegration
with that team_id
is created or updated.
Previously we only mass-updated "legacy" records, ones with no bot token data as the mass-update only set bot token data.
As the bot access token data is identical for SlackIntegration
records that share a team_id
, this meant that all the records correctly had the same bot access token data.
After !105439 (merged) we
now also save Slack permission scopes to these records. This scope data should also be updated across all records that share a team_id
, legacy or not, otherwise, customers will experience bugs.
This merge request updates all SlackIntegration
records that share a team_id
, rather than just "legacy" records. This will update the both bot access token data and scope data for these records. As mentioned, the bot access data should (and is) identical for all of these records anyway, but the change means that the scope data will also be identical now for all records.
Query change
Example raw SQL:
SELECT
"slack_integrations".*
FROM
"slack_integrations"
WHERE
"slack_integrations"."team_id" = 'bar'
AND "slack_integrations"."id" != 6
Query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/14595/commands/51133
Index Scan using index_slack_integrations_on_team_id_and_alias on public.slack_integrations (cost=0.42..3.44 rows=1 width=176) (actual time=1.891..1.892 rows=0 loops=1)
Index Cond: ((slack_integrations.team_id)::text = 'bar'::text)
Filter: (slack_integrations.id <> 6)
Rows Removed by Filter: 0
Buffers: shared read=3
I/O Timings: read=1.872 write=0.000
QA steps
To QA this feature you must have access to the Ecosystem Test Slack Workspace.
- Start a new GitPod instance and configure the GitLab for Slack (dev) app to work with it (docs)
- Checkout this feature branch,
bundle
andyarn
, and restart GDK (docs):cd /workspace/gitlab && git fetch origin 385760-mass-update-all-slack-integration-records-for-team && git checkout 385760-mass-update-all-slack-integration-records-for-team && bundle && yarn && cd /workspace/gitlab-development-kit && gdk restart
- Choose a project, and set up the Slack application integration.
- Choose a second project, and set up the Slack application integration.
- On the GitPod rails console, inspect both
SlackIntegration
records. They should share all information, including the sameupdated_at
timestamp. - QA that both integrations still work (test a slash commands, for example).
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #385760 (closed)