summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-07 10:54:13 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-07 10:54:13 +0200
commite4d8aa664a27566322f5071f8c353de6a0440b86 (patch)
tree086dd4f2f696546e5e013a7382e569f23fa6d381
parent5eca0ce3df1563a69803b64abc0b9ca863fa4836 (diff)
downloadgitlab-ce-fix/gb/stage-id-reference-background-migration.tar.gz
Add some comments on new migrations helpersfix/gb/stage-id-reference-background-migration
-rw-r--r--lib/gitlab/database/migration_helpers.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index b6883704da0..ca7e4c8aa7c 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -255,6 +255,25 @@ module Gitlab
end
end
+ ##
+ # Iterates a table and executes a block for given range.
+ #
+ # Yields batch index, start and stop ids.
+ #
+ # Optional `scope` keyword argument is a closure that is meant to limit
+ # the scope the statement is going to be applied onto.
+ #
+ # Arel statement this helper will execute must be defined inside the
+ # block.
+ #
+ # Example:
+ #
+ # scope = ->(table, query) { query.where(table[:id].gt(100) }
+ #
+ # walk_table_in_batches(:table, of: 10, scope: scope) do |index, start, stop|
+ # # do something here
+ # end
+ #
def walk_table_in_batches(table, of: 1000, scope: nil)
if transaction_open?
raise <<-MSG
@@ -287,6 +306,25 @@ module Gitlab
end
end
+ ##
+ # Executes an SQL statement in batches, created by Arel manager.
+ #
+ # Optional `scope` keyword argument is a closure that is meant to limit
+ # the scope the statement is going to be applied onto.
+ #
+ # Arel statement this helper will execute must be defined inside the
+ # block.
+ #
+ # Example:
+ #
+ # scope = ->(table, query) { query.where(table[:id].gt(100) }
+ #
+ # execute_in_batches(:table, of: 10000, scope: scope) do |table|
+ # Arel::UpdateManager.new(ActiveRecord::Base)
+ # .table(table)
+ # .set([[table[:field], 101]])
+ # end
+ #
def execute_in_batches(table, of: 1000, scope: nil)
if transaction_open?
raise <<-MSG