summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-06-13 11:38:57 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2016-06-13 11:38:57 +0200
commit9c238dc970afc4cc9e4e4f9e3327e7a34b8d7c9a (patch)
treebfa08219e8aa737f986ac1d21c2e37e929639f22
parentb33b7be53e113e4f07154b6aafb7858d76d99516 (diff)
downloadgitlab-ce-9c238dc970afc4cc9e4e4f9e3327e7a34b8d7c9a.tar.gz
Update columns in batches until no rows are left
Instead of updating a fixed number of rows (based on the amount of rows available at the start of the update) the method "update_column_in_batches" will now continue updating rows until it runs out of rows to process. For a table with a high rate of inserts this may result in the migration taking quite some time. However, the alternative is not all rows being updated or the "change_column_null" method raising an error due to there being NULL values.
-rw-r--r--lib/gitlab/database/migration_helpers.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index 0f488e968f6..ddf428e9cb4 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -55,10 +55,10 @@ module Gitlab
first['count'].
to_i
- # Update in batches of 5%
+ # Update in batches of 5% until we run out of any rows to update.
batch_size = ((total / 100.0) * 5.0).ceil
- while processed < total
+ loop do
start_row = exec_query(%Q{
SELECT id
FROM #{quoted_table}
@@ -66,6 +66,9 @@ module Gitlab
LIMIT 1 OFFSET #{processed}
}).to_hash.first
+ # There are no more rows to process
+ break unless start_row
+
stop_row = exec_query(%Q{
SELECT id
FROM #{quoted_table}