From 9c99f8829d400e748a409e679194222c8c8f36f9 Mon Sep 17 00:00:00 2001
From: Manoj M J <mmj@gitlab.com>
Date: Mon, 25 Mar 2024 13:16:41 +0100
Subject: [PATCH] Add sharding keys for navigation

Add sharding keys for feature category `navigation`.

These tables have been identified as
[cell local tables](https://docs.gitlab.com/ee/development/database/multiple_databases.html#guidelines-on-choosing-between-gitlab_main_cell-and-gitlab_main_clusterwide-schema).

All cell local tables require a
[sharding key](https://docs.gitlab.com/ee/development/database/multiple_databases.html#defining-a-sharding-key-for-all-cell-local-tables).

A sharding key has been automatically selected for these tables. The sharding key was chosen because it is a
`NOT NULL` column referencing either `projects` or `namespaces`.

Additionally, `gitlab_schema` has been set to `gitlab_main_cell` for any tables that didn't use this schema already.
For these tables we have also added `allow_cross_joins`, `allow_cross_transactions` and
`allow_cross_foreign_keys`. These will silence any existing violations, allowing the pipeline to pass without
requiring further changes. In the future, we'll remove these `allow_...` statements and fix any violations as
they arise. You can read more about this in the [documentation for multiple databases](https://docs.gitlab.com/ee/development/database/multiple_databases.html).

We have assigned a random backend engineer from ~"" to review these changes.
Please confirm that each table should indeed be cell local, and that the selected column is an appropriate
sharding key. When you are finished, please request a review from the database maintainer suggested by Danger.

If you have any questions or concerns, reach out to @tigerwnz or @DylanGriffith.

If you would like to go through similar merged MRs so as to gather an understanding on this topic, you
can use [this](https://gitlab.com/gitlab-org/gitlab/-/merge_requests?scope=all&state=merged&label_name[]=automation%3Agitlab-housekeeper-authored) link.

This change was generated by
[gitlab-housekeeper](https://gitlab.com/gitlab-org/gitlab/-/tree/master/gems/gitlab-housekeeper)
using the Keeps::DetermineShardingKeyFeatureCategory keep.

To provide feedback on your experience with `gitlab-housekeeper` please comment in
<https://gitlab.com/gitlab-org/gitlab/-/issues/442003>.

Changelog: other
---
 db/docs/group_features.yml        |  2 ++
 db/docs/groups_visits.yml         | 13 +++++++++++--
 db/docs/project_features.yml      |  5 ++++-
 db/docs/projects_visits.yml       | 13 +++++++++++--
 db/docs/user_group_callouts.yml   |  2 ++
 db/docs/user_project_callouts.yml | 10 +++++++++-
 6 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/db/docs/group_features.yml b/db/docs/group_features.yml
index b18074b07114e..0081fac356e9f 100644
--- a/db/docs/group_features.yml
+++ b/db/docs/group_features.yml
@@ -8,3 +8,5 @@ description: Stores access levels for group features, like the wiki
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82017
 milestone: '14.10'
 gitlab_schema: gitlab_main_cell
+sharding_key:
+  group_id: namespaces
diff --git a/db/docs/groups_visits.yml b/db/docs/groups_visits.yml
index 99e424d3946dd..54a11eeff5f31 100644
--- a/db/docs/groups_visits.yml
+++ b/db/docs/groups_visits.yml
@@ -4,7 +4,16 @@ classes:
 - Users::GroupVisit
 feature_categories:
 - navigation
-description: Tracks group visits so we can suggest groups that are recently and frequently visited.
+description: Tracks group visits so we can suggest groups that are recently and frequently
+  visited.
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/123554
 milestone: '16.4'
-gitlab_schema: gitlab_main
+gitlab_schema: gitlab_main_cell
+allow_cross_joins:
+- gitlab_main_clusterwide
+allow_cross_transactions:
+- gitlab_main_clusterwide
+allow_cross_foreign_keys:
+- gitlab_main_clusterwide
+sharding_key:
+  entity_id: namespaces
diff --git a/db/docs/project_features.yml b/db/docs/project_features.yml
index 78e20b04178f3..d9a79a771744b 100644
--- a/db/docs/project_features.yml
+++ b/db/docs/project_features.yml
@@ -4,7 +4,10 @@ classes:
 - ProjectFeature
 feature_categories:
 - navigation
-description: Stores access levels for project features like wikis, issues, repositories, containers, ect.
+description: Stores access levels for project features like wikis, issues, repositories,
+  containers, ect.
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/5606
 milestone: '8.12'
 gitlab_schema: gitlab_main_cell
+sharding_key:
+  project_id: projects
diff --git a/db/docs/projects_visits.yml b/db/docs/projects_visits.yml
index 23c10fd85683b..ce365db4be411 100644
--- a/db/docs/projects_visits.yml
+++ b/db/docs/projects_visits.yml
@@ -4,7 +4,16 @@ classes:
 - Users::ProjectVisit
 feature_categories:
 - navigation
-description: Tracks project visits so we can suggest projects that are recently and frequently visited.
+description: Tracks project visits so we can suggest projects that are recently and
+  frequently visited.
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/123554
 milestone: '16.4'
-gitlab_schema: gitlab_main
+gitlab_schema: gitlab_main_cell
+allow_cross_joins:
+- gitlab_main_clusterwide
+allow_cross_transactions:
+- gitlab_main_clusterwide
+allow_cross_foreign_keys:
+- gitlab_main_clusterwide
+sharding_key:
+  entity_id: projects
diff --git a/db/docs/user_group_callouts.yml b/db/docs/user_group_callouts.yml
index 188fd06e60bf4..351db883d7796 100644
--- a/db/docs/user_group_callouts.yml
+++ b/db/docs/user_group_callouts.yml
@@ -8,3 +8,5 @@ description: TODO
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68785
 milestone: '14.3'
 gitlab_schema: gitlab_main_cell
+sharding_key:
+  group_id: namespaces
diff --git a/db/docs/user_project_callouts.yml b/db/docs/user_project_callouts.yml
index 40ccfa243ac49..025e83166ba56 100644
--- a/db/docs/user_project_callouts.yml
+++ b/db/docs/user_project_callouts.yml
@@ -7,4 +7,12 @@ feature_categories:
 description: Adds the ability to track a user callout being dismissed by project
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/94144
 milestone: '15.3'
-gitlab_schema: gitlab_main
+gitlab_schema: gitlab_main_cell
+allow_cross_joins:
+- gitlab_main_clusterwide
+allow_cross_transactions:
+- gitlab_main_clusterwide
+allow_cross_foreign_keys:
+- gitlab_main_clusterwide
+sharding_key:
+  project_id: projects
-- 
GitLab