Commit 25cd5aa2 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Run two threads to improve migration running time

parent a7702271
......@@ -4,24 +4,38 @@ class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration
DOWNTIME = false
def up
execute <<-SQL.strip_heredoc
builds_service = spawn <<-SQL.strip_heredoc
DELETE FROM services
WHERE type = 'BuildsEmailService'
AND active = #{false_value}
AND properties = '{"notify_only_broken_builds":true}';
SQL
pipelines_service = spawn <<-SQL.strip_heredoc
DELETE FROM services
WHERE type = 'PipelinesEmailService'
AND active = #{false_value}
AND properties = '{"notify_only_broken_pipelines":true}';
SQL
[builds_service, pipelines_service].each(&:join)
end
def false_value
quote(false)
private
def spawn(query)
Thread.new do
ActiveRecord::Base.connection_pool.with_connection do
ActiveRecord::Base.connection.execute(query)
end
end
end
def quote(value)
ActiveRecord::Base.connection.quote(value)
end
def false_value
quote(false)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment