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

20220830061704_orphaned_invited_members_cleanup.rb « post_migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c52495101648e0456aa41860f7144ee94c2d64f0 (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
# frozen_string_literal: true

class OrphanedInvitedMembersCleanup < Gitlab::Database::Migration[2.0]
  disable_ddl_transaction!

  restrict_gitlab_migration gitlab_schema: :gitlab_main

  def up
    # rubocop:disable Style/SymbolProc
    membership.where(query_condition).each_batch(of: 100) do |relation|
      relation.delete_all
    end
    # rubocop:enable Style/SymbolProc
  end

  def down
    # This migration is irreversible
  end

  private

  def membership
    @membership ||= define_batchable_model('members')
  end

  def query_condition
    'invite_token IS NULL and invite_accepted_at IS NOT NULL AND user_id IS NULL'
  end
end