From 25cd5aa228ebe10ce9eabb17c75eb86e9d8c152c Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 6 Feb 2017 12:39:36 +0800 Subject: [PATCH] Run two threads to improve migration running time --- ..._remove_inactive_default_email_services.rb | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb b/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb index 18affebde73..dc7750f3244 100644 --- a/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb +++ b/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb @@ -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