VSA - Add sharding key for `analytics_cycle_analytics_stage_event_hashes` table

Overview

About GitLab Cells.

Tasks

The analytics_cycle_analytics_stage_event_hashes table contains global metadata which is associated with stage records (group-level). To make this table work with the org mover we need to alter the database schema.

Task: Add organization_id to the table

  1. Add organization_id to the analytics_cycle_analytics_stage_event_hashes table with default value 1.
  2. Change the unique index on hash_sha256 and scope it to the organization_id column.
  3. When a new record is created, set the organization ID using the association which creates the hash record.
       # in the ensure_stage_event_hash_id method
       stage = Stage.build(...)
       hash = Hash.create(organization_id: stage.group.organization_id, ...)
       stage.save!
  4. Update all queries where we load the hash records to be scoped to the associated namespace.organization_id.
  5. Configure the sharding key in the YML for analytics_cycle_analytics_stage_event_hashes.
Edited by Haim Snir