Skip to content

Ensure suggestions sharding key is set at the application level

What does this MR do and why?

This is part of the work needed for sharding the table suggestions (Re #550696):

Tasks MR
  • Add sharding key column namespace_id
  • Add a trigger to populate this column on insert and update
  • Add NOT VALID NOT NULL constraint
  • Create an index
  • Add NOT VALID foreign key

!207836 (merged)

  • Ensure namespace_id is set at the application level

🚧 !210092 (merged) 👈 we are here

  • Backfill namespace_id for existing records

!209953

  • Finalise backfilling migration
  • Validate NOT NULL constraint and foreign key
  • Update model validation to include all actions
TBD

Summary of changes

  • Add a before_validation callback to set namespace_id on create
  • Validate presence of namespace on create (unless the record is being imported)
  • Update Suggestions::CreateService to set namespace_id when creating a suggestion
  • Update specs to ensure the namespace_id value is being set for these records (including during a project import)

To note: In Suggestion#ensure_namespace_id, we have to check for note.project.project_namespace_id because note.namespace_id (that table sharding key) might not be present yet. We do know that these kinds of notes belong to a project, so if the note is present, we can fetch the namespace via its project.

References

Related to #572849

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugenia Grieff

Merge request reports

Loading