Unverified Commit 9c238dc9 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

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 73e94c566e2b
......@@ -55,10 +55,10 @@ def update_column_in_batches(table, column, value)
# 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{
FROM #{quoted_table}
......@@ -66,6 +66,9 @@ def update_column_in_batches(table, column, value)
LIMIT 1 OFFSET #{processed}
# There are no more rows to process
break unless start_row
stop_row = exec_query(%Q{
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