summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-14 15:08:04 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-14 15:08:04 +0000
commit8c4225a66b12683bcf1bba9bb9328fcf65395b6d (patch)
treed3b583abd26fcbbcbf0db828aee2b940414e1649 /spec/support
parent075c890053f626018ba680e4da21a93743acb244 (diff)
downloadgitlab-ce-8c4225a66b12683bcf1bba9bb9328fcf65395b6d.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/helpers/batch_destroy_dependent_associations_helper.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/support/helpers/batch_destroy_dependent_associations_helper.rb b/spec/support/helpers/batch_destroy_dependent_associations_helper.rb
new file mode 100644
index 00000000000..22170de053b
--- /dev/null
+++ b/spec/support/helpers/batch_destroy_dependent_associations_helper.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module BatchDestroyDependentAssociationsHelper
+ private
+
+ def delete_in_batches_regexps(table, column, resource, items, batch_size: 1000)
+ # rubocop:disable Layout/LineLength
+ select_query = %r{^SELECT "#{table}".* FROM "#{table}" WHERE.* "#{table}"."#{column}" = #{resource.id}.*ORDER BY "#{table}"."id" ASC LIMIT #{batch_size}}
+ # rubocop:enable Layout/LineLength
+
+ [select_query] + items.map { |item| %r{^DELETE FROM "#{table}" WHERE "#{table}"."id" = #{item.id}} }
+ end
+end