summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-11-17 11:10:14 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-11-17 11:10:14 +0000
commit2dff37762f76b195d6b36d73dab544d0ec5e6c83 (patch)
treeee3ae43cf986ae5ee83d0a16db44ea045bcb3b59 /lib
parent883d5da1a0cb505125d80f3705420581720b6124 (diff)
parent5cecff893db3188ff5ec779e07e9c598d3ed2e21 (diff)
downloadgitlab-ce-2dff37762f76b195d6b36d73dab544d0ec5e6c83.tar.gz
Merge branch 'sh-background-migration-move-mr-diff-id' into 'master'
Convert migration to populate latest merge request ID into a background migration See merge request gitlab-org/gitlab-ce!15440
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/background_migration/populate_merge_requests_latest_merge_request_diff_id.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/populate_merge_requests_latest_merge_request_diff_id.rb b/lib/gitlab/background_migration/populate_merge_requests_latest_merge_request_diff_id.rb
new file mode 100644
index 00000000000..7e109e96e73
--- /dev/null
+++ b/lib/gitlab/background_migration/populate_merge_requests_latest_merge_request_diff_id.rb
@@ -0,0 +1,30 @@
+module Gitlab
+ module BackgroundMigration
+ class PopulateMergeRequestsLatestMergeRequestDiffId
+ BATCH_SIZE = 1_000
+
+ class MergeRequest < ActiveRecord::Base
+ self.table_name = 'merge_requests'
+
+ include ::EachBatch
+ end
+
+ def perform(start_id, stop_id)
+ update = '
+ latest_merge_request_diff_id = (
+ SELECT MAX(id)
+ FROM merge_request_diffs
+ WHERE merge_requests.id = merge_request_diffs.merge_request_id
+ )'.squish
+
+ MergeRequest
+ .where(id: start_id..stop_id)
+ .where(latest_merge_request_diff_id: nil)
+ .each_batch(of: BATCH_SIZE) do |relation|
+
+ relation.update_all(update)
+ end
+ end
+ end
+ end
+end