Skip to content

Fix sharding key for p_ci_build_trace_metadata

Despite the backfill for p_ci_build_trace_metadata being finalized, we still see invalid records when adding NOT NULL constraint on the sharding key.

We might need to redo the backfill for this table and/or ensure that the triggers/callback to populate the sharding key on new rows is correct

Possible Solution:

  1. Update code paths that is settings the project_id to NULL and ensure that it is always set.
    • Update find_or_upsert_for! to set the correct project_id.
    • Move the set_project_id from before_validation to before_save and remove on: create.
    • Note: There may be other code paths that we haven't identified yet. Please take the time to trace other possible causes.
  2. Redo the sharding key backfill for the table.

Note: The alternative for (1) is to add a database trigger using install_sharding_key_assignment_trigger. Though this is less ideal because these triggers are meant to be temporary only meant to defer working on (1) at a later time.

Edited by Shane Maglangit