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

20220913030624_cleanup_attention_request_related_system_notes.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7d6908696b1929f76f20b1f60bc1914a277c150 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class CleanupAttentionRequestRelatedSystemNotes < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!
  restrict_gitlab_migration gitlab_schema: :gitlab_main

  BATCH_SIZE = 100

  class SystemNoteMetadata < MigrationRecord
    include EachBatch

    self.table_name = 'system_note_metadata'
  end

  class Note < MigrationRecord
    self.table_name = 'notes'
  end

  def up
    SystemNoteMetadata
      .where(action: %w[attention_requested attention_request_removed])
      .each_batch(of: BATCH_SIZE) do |batch|
        Note.where(id: batch.pluck(:note_id)).delete_all
      end
  end

  def down
    # no op
  end
end