From 1f423370129f073ded9ff2afdf2ebe58d21e2d29 Mon Sep 17 00:00:00 2001
From: Dylan Griffith <dyl.griffith@gmail.com>
Date: Wed, 7 Feb 2024 10:04:15 +0000
Subject: [PATCH] Add sharding keys for remote_development

Add sharding keys for feature category `remote_development`.

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 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 ~"group::ide" 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.

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

Changelog: other
---
 db/docs/remote_development_agent_configs.yml | 17 ++++++++++++++++-
 db/docs/workspace_variables.yml              | 17 ++++++++++++++++-
 db/docs/workspaces.yml                       | 10 +++++++++-
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/db/docs/remote_development_agent_configs.yml b/db/docs/remote_development_agent_configs.yml
index 89e8009558056..855389cf6235d 100644
--- a/db/docs/remote_development_agent_configs.yml
+++ b/db/docs/remote_development_agent_configs.yml
@@ -7,4 +7,19 @@ feature_categories:
 description: Remote Development Cluster Agent Configuration
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/105783
 milestone: '16.0'
-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
+desired_sharding_key:
+  project_id:
+    references: projects
+    backfill_via:
+      parent:
+        foreign_key: cluster_agent_id
+        table: cluster_agents
+        sharding_key: project_id
+        belongs_to: agent
diff --git a/db/docs/workspace_variables.yml b/db/docs/workspace_variables.yml
index f3eef551225eb..f92750f84c1d9 100644
--- a/db/docs/workspace_variables.yml
+++ b/db/docs/workspace_variables.yml
@@ -7,4 +7,19 @@ feature_categories:
 description: Remote Development Workspace variables
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/129688
 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
+desired_sharding_key:
+  project_id:
+    references: projects
+    backfill_via:
+      parent:
+        foreign_key: workspace_id
+        table: workspaces
+        sharding_key: project_id
+        belongs_to: workspace
diff --git a/db/docs/workspaces.yml b/db/docs/workspaces.yml
index 045a31d0d73ec..8aefb91c4de4b 100644
--- a/db/docs/workspaces.yml
+++ b/db/docs/workspaces.yml
@@ -7,4 +7,12 @@ feature_categories:
 description: Remote Development Workspaces
 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/105783
 milestone: '16.0'
-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