Add bot_namespace column and foreign key to user details
What does this MR do and why?
Related to Credentials inventory project and group access ... (#498333 - closed)
Project and Group Access Tokens have a project_bot user associated with them. The project_bot user is only allowed to be a member of a single group or project. Currently, the only association that indicates project bot (and project/group access token) ownership is that sole membership. Not only is this ambiguous/opaque, but it makes performant queries hard. Especially for the feature is question where we need the ability to query for all project_bot users, and subsequently all project access tokens owned by a given group hierarchy.
Our plan is to add a new column to user_details called bot_namespace which will be a foreign key and indicate the group or project (namespace) that owns the bot. With the change in this merge request we will be able to use a query such as User.joins(:user_detail).where(user_detail: { bot_namespace_id: group.self_and_descendants(skope: Namespace) }) to find all bot users.
This MR only adds the column, indexes, foreign key, and model associations. Two more MRs will be necessary to:
- Backfill this column
- Utilize the new column
Query plan for the above mentioned query: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/33029/commands/101753
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
| Before | After |
|---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.