Add and populate sharding key columns for uploads
What does this MR do and why?
This MR is the first step to add a sharding key to uploads
- #398199.
Add new organization_id
, namespace_id
, and project_id
columns to uploads
and populate them on create/update. For every model that is using uploads
, add a #uploads_sharding_key` method that will be used to populate the new columns.
All models that may use uploads
were found with the following script:
[1] pry(main)> Rails.application.eager_load!;
[2] pry(main)> all_models = ActiveRecord::Base.descendants.flat_map {|m| m.descendants};
[3] pry(main)> ap all_models.select {|m| (m.reflections.find {|_, r| r.class_name == 'Upload' && r.foreign_key == 'model_id'}) || (m.uploaders.values.any? {|u| u.included_modules.include?(RecordsUploads::Concern)})}.map(&:to_s).uniq.sort
[
[ 0] "AbuseReport",
[ 1] "Achievements::Achievement",
[ 2] "Ai::VectorizableFile",
[ 3] "AlertManagement::MetricImage",
[ 4] "Appearance",
[ 5] "BulkImports::ExportUpload",
[ 6] "Dependencies::DependencyListExport",
[ 7] "Dependencies::DependencyListExport::Part",
[ 8] "DesignManagement::Action",
[ 9] "DiffNote",
[10] "DiscussionNote",
[11] "Group",
[12] "ImportExportUpload",
[13] "IssuableMetricImage",
[14] "IterationNote",
[15] "LabelNote",
[16] "LegacyDiffNote",
[17] "MilestoneNote",
[18] "Note",
[19] "Organizations::OrganizationDetail",
[20] "PersonalSnippet",
[21] "Project",
[22] "Projects::ImportExport::RelationExportUpload",
[23] "Projects::Topic",
[24] "StateNote",
[25] "SyntheticNote",
[26] "User",
[27] "UserPermissionExportUpload",
[28] "Vulnerabilities::Export",
[29] "Vulnerabilities::Export::Part",
[30] "Vulnerabilities::Remediation",
[31] "WeightNote"
]
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.
Related to #398199
Edited by Krasimir Angelov