Draft: Add sharding key trigger and backfill for bulk_import_export_batches.organization_id

What does this MR do and why?

Part 2 of 2: Trigger + batched background migration to backfill bulk_import_export_batches.organization_id

Second step toward an organization_id sharding key on bulk_import_export_batches for issue #603592 (closed), mirroring merged !241089 (merged) (parent table, #600457 (closed)):

  • Installs a sharding key assignment trigger via the shared install_sharding_key_assignment_trigger helper (single-hop: copies organization_id from the related bulk_import_exports row via export_id)
  • Queues the BackfillBulkImportExportBatchesOrganizationId batched background migration (batch_size: 1000, sub_batch_size: 100, gitlab_main_org)
  • The BBM job touches updated_at on rows with organization_id IS NULL and lets the trigger derive the value (same approach as the parent job)

NOT NULL constraint, FK validation, and the sharding_key: db/docs switch are deliberately out of scope; they land in the finalize step, #603593 (closed).

Note for reviewers: this is a stacked MR. It is based on and targets the branch of Part 1: !243557 (closed). Please review that one first.

Migration details

db/post_migrate/20260702130000_add_sharding_key_trigger_on_bulk_import_export_batches.rb
db/post_migrate/20260702130001_queue_backfill_bulk_import_export_batches_organization_id.rb

MR acceptance checklist

  • Migrations tested up and down locally
  • Database review

References

Merge request reports

Loading
Loading