Run two threads to improve migration running time
This commit is contained in:
parent
a770227139
commit
25cd5aa228
1 changed files with 17 additions and 3 deletions
|
@ -4,24 +4,38 @@ class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration
|
||||||
DOWNTIME = false
|
DOWNTIME = false
|
||||||
|
|
||||||
def up
|
def up
|
||||||
execute <<-SQL.strip_heredoc
|
builds_service = spawn <<-SQL.strip_heredoc
|
||||||
DELETE FROM services
|
DELETE FROM services
|
||||||
WHERE type = 'BuildsEmailService'
|
WHERE type = 'BuildsEmailService'
|
||||||
AND active = #{false_value}
|
AND active = #{false_value}
|
||||||
AND properties = '{"notify_only_broken_builds":true}';
|
AND properties = '{"notify_only_broken_builds":true}';
|
||||||
|
SQL
|
||||||
|
|
||||||
|
pipelines_service = spawn <<-SQL.strip_heredoc
|
||||||
DELETE FROM services
|
DELETE FROM services
|
||||||
WHERE type = 'PipelinesEmailService'
|
WHERE type = 'PipelinesEmailService'
|
||||||
AND active = #{false_value}
|
AND active = #{false_value}
|
||||||
AND properties = '{"notify_only_broken_pipelines":true}';
|
AND properties = '{"notify_only_broken_pipelines":true}';
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
|
[builds_service, pipelines_service].each(&:join)
|
||||||
end
|
end
|
||||||
|
|
||||||
def false_value
|
private
|
||||||
quote(false)
|
|
||||||
|
def spawn(query)
|
||||||
|
Thread.new do
|
||||||
|
ActiveRecord::Base.connection_pool.with_connection do
|
||||||
|
ActiveRecord::Base.connection.execute(query)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def quote(value)
|
def quote(value)
|
||||||
ActiveRecord::Base.connection.quote(value)
|
ActiveRecord::Base.connection.quote(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def false_value
|
||||||
|
quote(false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue