summaryrefslogtreecommitdiff
path: root/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb
blob: f221dac8e208eee4c0b2ad3dcd3a6689bd911c2c (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
29
30
31
32
33
34
35
36
37
38
39
40
41
class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration[4.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    Gitlab::Database.with_connection_pool(2) do |pool|
      threads = []

      threads << Thread.new do
        pool.with_connection do |connection|
          connection.execute <<-SQL.strip_heredoc
          DELETE FROM services
            WHERE type = 'BuildsEmailService'
              AND active IS FALSE
              AND properties = '{"notify_only_broken_builds":true}';
          SQL
        end
      end

      threads << Thread.new do
        pool.with_connection do |connection|
          connection.execute <<-SQL.strip_heredoc
          DELETE FROM services
            WHERE type = 'PipelinesEmailService'
              AND active IS FALSE
              AND properties = '{"notify_only_broken_pipelines":true}';
          SQL
        end
      end

      threads.each(&:join)
    end
  end

  def down
    # Nothing can be done to restore the records
  end
end