summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb')
-rw-r--r--db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb b/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb
new file mode 100644
index 00000000000..f350fbe3d12
--- /dev/null
+++ b/db/post_migrate/20210825193652_backfill_cadence_id_for_boards_scoped_to_iteration.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+class BackfillCadenceIdForBoardsScopedToIteration < Gitlab::Database::Migration[1.0]
+ disable_ddl_transaction!
+
+ BATCH_SIZE = 1000
+ DELAY = 2.minutes.to_i
+ MIGRATION = 'BackfillIterationCadenceIdForBoards'
+
+ class MigrationBoard < ApplicationRecord
+ include EachBatch
+
+ self.table_name = 'boards'
+ end
+
+ def up
+ schedule_backfill_group_boards
+ schedule_backfill_project_boards
+ end
+
+ def down
+ MigrationBoard.where.not(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first
+ delay = index * DELAY
+
+ migrate_in(delay, MIGRATION, ['none', 'down', *range])
+ end
+ end
+
+ private
+
+ def schedule_backfill_project_boards
+ MigrationBoard.where(iteration_id: -4).where.not(project_id: nil).where(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first
+ delay = index * DELAY
+
+ migrate_in(delay, MIGRATION, ['project', 'up', *range])
+ end
+ end
+
+ def schedule_backfill_group_boards
+ MigrationBoard.where(iteration_id: -4).where.not(group_id: nil).where(iteration_cadence_id: nil).each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first
+ delay = index * DELAY
+
+ migrate_in(delay, MIGRATION, ['group', 'up', *range])
+ end
+ end
+end