2017-02-06 04:22:55 +00:00
|
|
|
class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
def up
|
2017-02-06 04:39:36 +00:00
|
|
|
builds_service = spawn <<-SQL.strip_heredoc
|
2017-02-06 04:22:55 +00:00
|
|
|
DELETE FROM services
|
|
|
|
WHERE type = 'BuildsEmailService'
|
|
|
|
AND active = #{false_value}
|
|
|
|
AND properties = '{"notify_only_broken_builds":true}';
|
2017-02-06 04:39:36 +00:00
|
|
|
SQL
|
2017-02-06 04:22:55 +00:00
|
|
|
|
2017-02-06 04:39:36 +00:00
|
|
|
pipelines_service = spawn <<-SQL.strip_heredoc
|
2017-02-06 04:22:55 +00:00
|
|
|
DELETE FROM services
|
|
|
|
WHERE type = 'PipelinesEmailService'
|
|
|
|
AND active = #{false_value}
|
|
|
|
AND properties = '{"notify_only_broken_pipelines":true}';
|
|
|
|
SQL
|
2017-02-06 04:39:36 +00:00
|
|
|
|
|
|
|
[builds_service, pipelines_service].each(&:join)
|
2017-02-06 04:22:55 +00:00
|
|
|
end
|
|
|
|
|
2017-02-06 04:39:36 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def spawn(query)
|
|
|
|
Thread.new do
|
|
|
|
ActiveRecord::Base.connection_pool.with_connection do
|
|
|
|
ActiveRecord::Base.connection.execute(query)
|
|
|
|
end
|
|
|
|
end
|
2017-02-06 04:22:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def quote(value)
|
|
|
|
ActiveRecord::Base.connection.quote(value)
|
|
|
|
end
|
2017-02-06 04:39:36 +00:00
|
|
|
|
|
|
|
def false_value
|
|
|
|
quote(false)
|
|
|
|
end
|
2017-02-06 04:22:55 +00:00
|
|
|
end
|