debian-mirror-gitlab/lib/gitlab/background_migration/add_merge_request_diff_commits_count.rb

26 lines
766 B
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
# frozen_string_literal: true
# rubocop:disable Style/Documentation
module Gitlab
module BackgroundMigration
class AddMergeRequestDiffCommitsCount
class MergeRequestDiff < ActiveRecord::Base
self.table_name = 'merge_request_diffs'
end
def perform(start_id, stop_id)
2020-11-24 15:15:51 +05:30
Gitlab::AppLogger.info("Setting commits_count for merge request diffs: #{start_id} - #{stop_id}")
2018-03-17 18:26:18 +05:30
update = '
commits_count = (
SELECT count(*)
FROM merge_request_diff_commits
WHERE merge_request_diffs.id = merge_request_diff_commits.merge_request_diff_id
)'.squish
2018-05-09 12:01:36 +05:30
MergeRequestDiff.where(id: start_id..stop_id).where(commits_count: nil).update_all(update)
2018-03-17 18:26:18 +05:30
end
end
end
end