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

20200312053852_populate_canonical_emails.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10efffab59c79c88ca953b86ee2b3ad84db3f38c (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
31
32
33
34
35
# frozen_string_literal: true

class PopulateCanonicalEmails < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  class User < ActiveRecord::Base
    include EachBatch

    self.table_name = 'users'

    scope :with_gmail, -> { select(:id, :email).where("email ILIKE '%gmail.com'") }
  end

  # Limited to *@gmail.com addresses only as a first iteration, because we know
  # Gmail ignores `.` appearing in the Agent name, as well as anything after `+`

  def up
    # batch size is the default, 1000
    migration = Gitlab::BackgroundMigration::PopulateCanonicalEmails
    migration_name = migration.to_s.demodulize

    queue_background_migration_jobs_by_range_at_intervals(
      User.with_gmail,
      migration_name,
      1.minute)
  end

  def down
    # no-op
  end
end