summaryrefslogtreecommitdiff
path: root/db/post_migrate/20200128133510_cleanup_empty_commit_user_mentions.rb
blob: 362aa3a60f7af0e5fba84c6678b12c921095a613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

class CleanupEmptyCommitUserMentions < ActiveRecord::Migration[5.2]
  DOWNTIME = false
  BATCH_SIZE = 10_000

  class CommitUserMention < ActiveRecord::Base
    include EachBatch

    self.table_name = 'commit_user_mentions'
  end

  def up
    # cleanup commit user mentions with no actual mentions,
    # re https://gitlab.com/gitlab-org/gitlab/-/merge_requests/24586#note_285982468
    CommitUserMention
      .where(mentioned_users_ids: nil)
      .where(mentioned_groups_ids: nil)
      .where(mentioned_projects_ids: nil)
      .each_batch(of: BATCH_SIZE) do |batch|
      batch.delete_all
    end
  end

  def down
    # no-op
  end
end