diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-01-18 21:10:38 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-01-18 21:10:38 +0300 |
commit | 792e9ed7fa46d236c01fb14c8ad7f9b4ea4dee59 (patch) | |
tree | f9db61a037c3a93a8897f3df685242fba71a770a /lib | |
parent | 7b0872c7237a21eacd076b09be5712a4ef63b99f (diff) | |
parent | 0054d3838c07ece45d47086b7fe75aa4cf70726b (diff) |
Merge branch 'background-migration-fix' into 'master'
Reduce UPDATEs for background column type changes
Closes #42158
See merge request gitlab-org/gitlab-ce!16551
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/background_migration/copy_column.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 5 |
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/gitlab/background_migration/copy_column.rb b/lib/gitlab/background_migration/copy_column.rb index a2cb215c230..ef70f37d5eb 100644 --- a/lib/gitlab/background_migration/copy_column.rb +++ b/lib/gitlab/background_migration/copy_column.rb @@ -28,6 +28,8 @@ module Gitlab UPDATE #{quoted_table} SET #{quoted_copy_to} = #{quoted_copy_from} WHERE id BETWEEN #{start_id} AND #{end_id} + AND #{quoted_copy_from} IS NOT NULL + AND #{quoted_copy_to} IS NULL SQL end diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 592a1956ceb..dbe6259fce7 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -525,8 +525,9 @@ module Gitlab install_rename_triggers(table, column, temp_column) # Schedule the jobs that will copy the data from the old column to the - # new one. - relation.each_batch(of: batch_size) do |batch, index| + # new one. Rows with NULL values in our source column are skipped since + # the target column is already NULL at this point. + relation.where.not(column => nil).each_batch(of: batch_size) do |batch, index| start_id, end_id = batch.pluck('MIN(id), MAX(id)').first max_index = index |