diff options
Diffstat (limited to 'db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb')
-rw-r--r-- | db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb b/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb new file mode 100644 index 00000000000..8838a27f233 --- /dev/null +++ b/db/post_migrate/20220315181136_backfill_work_item_type_id_on_issues.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class BackfillWorkItemTypeIdOnIssues < Gitlab::Database::Migration[1.0] + MIGRATION = 'BackfillWorkItemTypeIdForIssues' + BATCH_CLASS_NAME = 'BackfillIssueWorkItemTypeBatchingStrategy' + BATCH_SIZE = 10_000 + MAX_BATCH_SIZE = 30_000 + SUB_BATCH_SIZE = 100 + INTERVAL = 2.minutes + + class MigrationWorkItemType < ApplicationRecord + self.table_name = 'work_item_types' + + def self.id_by_type + where(namespace_id: nil).order(:base_type).pluck(:base_type, :id).to_h + end + end + + def up + # We expect no more than 5 types. Only 3 of them are expected to have associated issues at the moment + MigrationWorkItemType.id_by_type.each do |base_type, type_id| + queue_batched_background_migration( + MIGRATION, + :issues, + :id, + base_type, + type_id, + job_interval: INTERVAL, + batch_size: BATCH_SIZE, + max_batch_size: MAX_BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE, + batch_class_name: BATCH_CLASS_NAME + ) + end + end + + def down + Gitlab::Database::BackgroundMigration::BatchedMigration.where(job_class_name: MIGRATION).delete_all + end +end |