Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
84265775
Commit
84265775
authored
Jul 07, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some comments on new migrations helpers
parent
fb89ba24
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+38
-0
No files found.
lib/gitlab/database/migration_helpers.rb
View file @
84265775
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment