Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20210428151144_update_invalid_web_hooks.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4f45e7aaa9b56cce72c9be09b37b6d8f1766ba93 (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
# frozen_string_literal: true

class UpdateInvalidWebHooks < ActiveRecord::Migration[6.0]
  disable_ddl_transaction!

  class WebHook < ActiveRecord::Base
    include EachBatch

    self.table_name = 'web_hooks'
  end

  def up
    WebHook.each_batch(of: 10_000, column: :id) do |relation|
      relation.where(type: 'ProjectHook')
              .where.not(project_id: nil)
              .where.not(group_id: nil)
              .update_all(group_id: nil)
    end
  end

  def down
    # no-op
  end
end