diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-13 11:38:57 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-13 11:38:57 +0200 |
commit | 9c238dc970afc4cc9e4e4f9e3327e7a34b8d7c9a (patch) | |
tree | bfa08219e8aa737f986ac1d21c2e37e929639f22 /lib/gitlab/database | |
parent | b33b7be53e113e4f07154b6aafb7858d76d99516 (diff) | |
download | gitlab-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.
Diffstat (limited to 'lib/gitlab/database')
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 7 |
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} |