summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/dynamic_model_helpers.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
commita5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch)
treefb69158581673816a8cd895f9d352dcb3c678b1e /lib/gitlab/database/dynamic_model_helpers.rb
parentd16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff)
downloadgitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'lib/gitlab/database/dynamic_model_helpers.rb')
-rw-r--r--lib/gitlab/database/dynamic_model_helpers.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/gitlab/database/dynamic_model_helpers.rb b/lib/gitlab/database/dynamic_model_helpers.rb
index 892f8291780..7439591be99 100644
--- a/lib/gitlab/database/dynamic_model_helpers.rb
+++ b/lib/gitlab/database/dynamic_model_helpers.rb
@@ -11,6 +11,25 @@ module Gitlab
self.inheritance_column = :_type_disabled
end
end
+
+ def each_batch(table_name, scope: ->(table) { table.all }, of: 1000)
+ if transaction_open?
+ raise <<~MSG.squish
+ each_batch should not run inside a transaction, you can disable
+ transactions by calling disable_ddl_transaction! in the body of
+ your migration class
+ MSG
+ end
+
+ scope.call(define_batchable_model(table_name))
+ .each_batch(of: of) { |batch| yield batch }
+ end
+
+ def each_batch_range(table_name, scope: ->(table) { table.all }, of: 1000)
+ each_batch(table_name, scope: scope, of: of) do |batch|
+ yield batch.pluck('MIN(id), MAX(id)').first
+ end
+ end
end
end
end