Mass-update related SlackIntegration records
What does this MR do and why?
When a user installs our Slack App, or re-installs it, we use SlackApplicationInstallService
to capture a bot access token for them in a SlackIntegration
record.
Due to the current modelling, for each project that a Slack Workspace integrates the Slack App with, a SlackIntegration
record is created. The bot access token will be the same for all SlackIntegration
records for the same Slack Workspace (team_id
).
Although the modelling is not ideal, at least every SlackIntegration
record can be used to find the bot access token for the Slack Workspace.
However, SlackIntegration
records created before we upgraded our Slack App to Granular Bot Permissions !85726 (merged) do not have bot access tokens.
This change updates any of these legacy records to have the bot access token.
This saves the need for users who installed our Slack App before we updated to use Granular Bot Permissions to need to re-install the Slack App manually for each project they integrate Slack with in order to use features that require the bot access token.
In future, we may refactor the modelling so there is only one record created per Slack Workspace which would do away with this need #357221 (closed).
SQL
SELECT
"slack_integrations".*
FROM
"slack_integrations"
WHERE
"slack_integrations"."team_id" = '<team_id>'
AND "slack_integrations"."bot_user_id" IS NULL
Where <team_id>
was the team_id
with the most slack_integrations
records !96208 (comment 1084558319).
Query plan:
https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/11807/commands/41844
Index Scan using index_slack_integrations_on_team_id_and_alias on public.slack_integrations (cost=0.41..224.38 rows=151 width=176) (actual time=45.710..65.315 rows=157 loops=1)
Index Cond: ((slack_integrations.team_id)::text = 'T0MU897PZ'::text)
Filter: (slack_integrations.bot_user_id IS NULL)
Rows Removed by Filter: 0
Buffers: shared hit=11 read=12
I/O Timings: read=65.053 write=0.000
How to set up and validate locally
- Follow the Integrations Slack guide to stand up a GitPod instance that can integrate with the development Slack App. As mentioned in the guide, you will need access to the Ecosystems Slack Workspace.
- On your GitPod instance terminal:
- Check out this feature branch:
cd /workspace/gitlab && git checkout 361732-mass-update-related-SlackIntegration-records-for-team
- Ensure yarn and gems are installed (the branch's versions can be behind
master
):cd /workspace/gitlab && yarn && bundle
. - Enable the feature flag:
cd /workspace/gitlab && bundle exec rails c
, thenFeature.enable(:update_legacy_slack_installations)
- Restart GDK:
cd /workspace/gitlab-development-kit && gdk restart
- Check out this feature branch:
- Visit your GitPod instance server
https://<your-unique>.gitpod.io
:- Choose a project, go
Settings > Integrations
, chooseSlack application
and click the button to install the Slack app.
- Choose a project, go
- To simulate a legacy
SlackIntegration
record, on your GitPod instance terminal:- Start a rails console:
cd /workspace/gitlab && bundle exec rails c
. - Nullify some of the record:
SlackIntegration.first.update!(bot_user_id: nil, bot_access_token: nil)
- Start a rails console:
- Choose a second project now, and also click the button to install the Slack app.
2. On the rails console inspect both
SlackIntegration
records. They should now share the samebot_access_token
,bot_user_id
,user_id
andupdated_at
properties.
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 #361732 (closed)