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

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

class MigrateRemainingU2fRegistrations < Gitlab::Database::Migration[1.0]
  BATCH_SIZE = 100

  disable_ddl_transaction!

  def up
    # We expect only a few number of records satisfying these conditions.
    # on gitlab.com database, this number is 70 as on 17th Nov, 2021.
    define_batchable_model('u2f_registrations')
        .joins("LEFT JOIN webauthn_registrations ON webauthn_registrations.u2f_registration_id = u2f_registrations.id")
        .where(webauthn_registrations: { u2f_registration_id: nil })
        .each_batch(of: BATCH_SIZE) do |batch, index|
      batch.each do |record|
        Gitlab::BackgroundMigration::MigrateU2fWebauthn.new.perform(record.id, record.id)
      rescue StandardError => e
        Gitlab::ErrorTracking.track_exception(e, u2f_registration_id: record.id)
      end
    end
  end

  def down
    # no-op
  end
end