summaryrefslogtreecommitdiff
path: root/db/migrate/20210428151144_update_invalid_web_hooks.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20210428151144_update_invalid_web_hooks.rb')
-rw-r--r--db/migrate/20210428151144_update_invalid_web_hooks.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/db/migrate/20210428151144_update_invalid_web_hooks.rb b/db/migrate/20210428151144_update_invalid_web_hooks.rb
new file mode 100644
index 00000000000..4f45e7aaa9b
--- /dev/null
+++ b/db/migrate/20210428151144_update_invalid_web_hooks.rb
@@ -0,0 +1,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