Define a sharding key for snippet_repositories
Table snippet_repositories should meet the guidelines for sharding so it can be linked to an Organization: https://docs.gitlab.com/development/organization/#defining-a-sharding-key-for-all-organizational-tables
When the work is complete, the new column should fulfil the following criteria:
-
has no default -
is not nullable -
has a foreign key to organizations
Deliverables
[UPDATE]
It turns out this case is more complex than the original steps we have outlined here. I have added the remaining steps below. I will create new issues for each of them to link to.
I have copied these steps from @olaoluro's similar work here: #522958 (closed) as we have established it is an acceptable outline for this work (see comment on this issue: #550705 (comment 2758040195)). I have added a few extra steps that were discovered along the way.
-
Add organization_idtosnippet_repositories,NULL, has no default, has a foreign key to organizations: -
Add support in code for new column organization_idonsnippet_repositories: -
Backfill snippet_repositoriesrecords withorganization_id: -
Finalize BBM above -
Add validations in code for new column organization_idonsnippet_repositoriesafter backfill: -
Add the NOT NULLconstraint (after backfill migration is done) to move closer to sharding goal -
Handle shard_id FK (multi step process) -
Remove NOT NULL constraint from shard_idcolumn. Issue: Remove NOT NULL constraint from snippet_reposit... (#577964 - closed) -
Update LFK script to allow us to run LFK script on some ON DELETE RESTRICTcolumns. Issue: Replace `shard_id` FK with LFK for snippet_repo... (!209036 - merged) -
Run LFK script on snippet_repositories.shard_id. This is being handled in the same MR/update as the script update: Replace `shard_id` FK with LFK for snippet_repo... (!209036 - merged)
-
-
Add organization_idsharding key (this issue)
Edited by Hunter Stewart