Class: Gitlab::BackgroundMigration::AddMergeRequestDiffCommitsCount

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/add_merge_request_diff_commits_count.rb

Defined Under Namespace

Classes: MergeRequestDiff

Instance Method Summary collapse

Instance Method Details

#perform(start_id, stop_id) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/background_migration/add_merge_request_diff_commits_count.rb', line 11

def perform(start_id, stop_id)
  Gitlab::AppLogger.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).where(commits_count: nil).update_all(update)
end