diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-01-11 12:39:23 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-01-11 12:39:23 +0000 |
commit | 0a51eae58642d2c1df27166092efa2d75ec1cbe0 (patch) | |
tree | d76583f425e49e1c1417cafdecf96059e949b93a /lib | |
parent | ec94d906b7cb3e5854834e823318a32e161e30a0 (diff) | |
parent | e6a1db6d9e3036ae0c9dc677f9029f5acf37f9f6 (diff) | |
download | gitlab-ce-0a51eae58642d2c1df27166092efa2d75ec1cbe0.tar.gz |
Merge branch '38068-commits-count' into 'master'
Resolve "Store the number of merge request commits in merge_request_diffs.commits_count"
Closes #38068
See merge request gitlab-org/gitlab-ce!16164
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/background_migration/add_merge_request_diff_commits_count.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/add_merge_request_diff_commits_count.rb b/lib/gitlab/background_migration/add_merge_request_diff_commits_count.rb new file mode 100644 index 00000000000..7bffffec94d --- /dev/null +++ b/lib/gitlab/background_migration/add_merge_request_diff_commits_count.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation +# rubocop:disable Metrics/LineLength + +module Gitlab + module BackgroundMigration + class AddMergeRequestDiffCommitsCount + class MergeRequestDiff < ActiveRecord::Base + self.table_name = 'merge_request_diffs' + end + + def perform(start_id, stop_id) + Rails.logger.info("Setting commits_count for merge request diffs: #{start_id} - #{stop_id}") + + update = ' + commits_count = ( + SELECT count(*) + FROM merge_request_diff_commits + WHERE merge_request_diffs.id = merge_request_diff_commits.merge_request_diff_id + )'.squish + + MergeRequestDiff.where(id: start_id..stop_id).update_all(update) + end + end + end +end |