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>2024-01-16 13:42:19 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2024-01-16 13:42:19 +0300
commit84d1bd786125c1c14a3ba5f63e38a4cc736a9027 (patch)
treef550fa965f507077e20dbb6d61a8269a99ef7107 /db/post_migrate/20231207145335_cleanup_group_level_work_items.rb
parent3a105e36e689f7b75482236712f1a47fd5a76814 (diff)
Add latest changes from gitlab-org/gitlab@16-8-stable-eev16.8.0-rc42
Diffstat (limited to 'db/post_migrate/20231207145335_cleanup_group_level_work_items.rb')
-rw-r--r--db/post_migrate/20231207145335_cleanup_group_level_work_items.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/db/post_migrate/20231207145335_cleanup_group_level_work_items.rb b/db/post_migrate/20231207145335_cleanup_group_level_work_items.rb
new file mode 100644
index 00000000000..d52f0518f44
--- /dev/null
+++ b/db/post_migrate/20231207145335_cleanup_group_level_work_items.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+class CleanupGroupLevelWorkItems < Gitlab::Database::Migration[2.2]
+ milestone '16.8'
+ restrict_gitlab_migration gitlab_schema: :gitlab_main
+ disable_ddl_transaction!
+
+ BATCH_SIZE = 100
+
+ class MigrationIssue < MigrationRecord
+ self.table_name = :issues
+
+ include EachBatch
+ end
+
+ class MigrationNote < MigrationRecord
+ self.table_name = :notes
+
+ include EachBatch
+ end
+
+ class MigrationLabelLink < MigrationRecord
+ self.table_name = :label_links
+
+ include EachBatch
+ end
+
+ class MigrationTodo < MigrationRecord
+ self.table_name = :todos
+
+ include EachBatch
+ end
+
+ def up
+ MigrationIssue.where(project_id: nil).each_batch(of: BATCH_SIZE) do |batch|
+ logger.info("deleting #{batch.size} issues at group level: #{batch.pluck(:id)}")
+
+ # cleaning up notes for the batch of issues
+ MigrationNote.where(noteable_type: 'Issue', noteable_id: batch).each_batch(of: BATCH_SIZE) do |note_batch|
+ logger.info("deleting #{note_batch.size} notes for issues at group level: #{note_batch.pluck(:id)}")
+ note_batch.delete_all
+ end
+
+ # cleaning up label links for the batch of issues
+ MigrationLabelLink.where(target_type: 'Issue', target_id: batch).each_batch(of: BATCH_SIZE) do |label_link_batch|
+ logger.info(
+ "deleting #{label_link_batch.size} label links for issues at group level: #{label_link_batch.pluck(:id)}"
+ )
+ label_link_batch.delete_all
+ end
+
+ # cleaning up todos for the batch of issues
+ MigrationTodo.where(target_type: 'Issue', target_id: batch).each_batch(of: BATCH_SIZE) do |todo_batch|
+ logger.info("deleting #{todo_batch.size} todos for issues at group level: #{todo_batch.pluck(:id)}")
+ todo_batch.delete_all
+ end
+
+ batch.delete_all
+ end
+ end
+
+ def down
+ # no-op
+ end
+
+ private
+
+ def logger
+ @logger ||= Gitlab::BackgroundMigration::Logger.build
+ end
+end