Make target_project_id as sharding_key for merge_requests_compliance_violations
As discussed in !154573 (comment 1930281243), we already have a column target_project_id
in merge_requests_compliance_violations
table, which can be used as sharding_key for the table as it stores the project id of the related merge request.
Currently we cannot use it as sharding_key because it is not marked as NOT NULL
and a constraint should be added to this field. For that, we would have to do following:
- Add an association between
target_project
andcompliance_violation
at https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/models/merge_requests/compliance_violation.rb#L33
belongs_to :target_project, class_name: 'Project', optional: false
- Add a background batched migration to make sure that the column is not null for any row of the table, it is not on gitlab.com as per https://console.postgres.ai/gitlab/gitlab-production-main/sessions/28702/commands/89427.
- Add a migration for adding
NOT NULL
constraint ontarget_project_id
column of themerge_requests_compliance_violations
table. - Update
https://gitlab.com/gitlab-org/gitlab/-/edit/master/db/docs/merge_requests_compliance_violations.yml
to set
sharding_key:
target_project_id: projects
Edited by Manoj M J