Commit 9c238dc9 authored by Yorick Peterse's avatar Yorick Peterse

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.
parent b33b7be5
......@@ -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}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment