Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-21 12:09:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-21 12:09:01 +0300
commita53d2c37c4934f564caa94543dd4cf5af1703e2d (patch)
treea028dc39771a4612a9845ab700a73af2d6f3f51b /lib/gitlab/background_migration
parent18b8435318887d3fc6e9f9d305967a953cdd7d3f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb b/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb
new file mode 100644
index 00000000000..3aa1ebb49f9
--- /dev/null
+++ b/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+# rubocop:disable Style/Documentation
+
+module Gitlab
+ module BackgroundMigration
+ class CleanupOptimisticLockingNulls
+ QUERY_ITEM_SIZE = 1_000
+
+ # table - The name of the table the migration is performed for.
+ # start_id - The ID of the object to start at
+ # stop_id - The ID of the object to end at
+ def perform(start_id, stop_id, table)
+ model = define_model_for(table)
+
+ # After analysis done, a batch size of 1,000 items per query was found to be
+ # the most optimal. Discussion in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/18418#note_282285336
+ (start_id..stop_id).each_slice(QUERY_ITEM_SIZE).each do |range|
+ model
+ .where(lock_version: nil)
+ .where(id: range)
+ .update_all(lock_version: 0)
+ end
+ end
+
+ def define_model_for(table)
+ Class.new(ActiveRecord::Base) do
+ self.table_name = table
+ end
+ end
+ end
+ end
+end