BigW Consortium Gitlab

20170206040400_remove_inactive_default_email_services.rb 1.02 KB
Newer Older
1 2 3 4 5
class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

6
  disable_ddl_transaction!
7

8
  def up
9 10 11 12 13 14 15 16 17 18 19 20
    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
21
      end
22

23 24 25 26 27 28 29 30 31
      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
32 33
      end

34 35
      threads.each(&:join)
    end
36 37
  end

38 39
  def down
    # Nothing can be done to restore the records
40
  end
41
end