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>2020-04-09 15:09:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 15:09:24 +0300
commita9ced7da447785c57477b3d8dbccc73a78cface1 (patch)
tree5179d27ab9d801748ee4ed1c64c985974e799812 /lib/gitlab/background_migration
parentad0265eead72a624ce7a020847db4f0f0c877e57 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/background_migration')
-rw-r--r--lib/gitlab/background_migration/populate_canonical_emails.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/populate_canonical_emails.rb b/lib/gitlab/background_migration/populate_canonical_emails.rb
new file mode 100644
index 00000000000..052e75c5655
--- /dev/null
+++ b/lib/gitlab/background_migration/populate_canonical_emails.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # Class to populate new rows of UserCanonicalEmail based on existing email addresses
+ class PopulateCanonicalEmails
+ def perform(start_id, stop_id)
+ ActiveRecord::Base.connection.execute <<~SQL
+ INSERT INTO
+ user_canonical_emails (
+ user_id,
+ canonical_email,
+ created_at,
+ updated_at
+ )
+ SELECT users.id AS user_id,
+ concat(translate(split_part(split_part(users.email, '@', 1), '+', 1), '.', ''), '@gmail.com') AS canonical_email,
+ NOW() AS created_at,
+ NOW() AS updated_at
+ FROM users
+ WHERE users.email ILIKE '%@gmail.com'
+ AND users.id BETWEEN #{start_id} AND #{stop_id}
+ ON CONFLICT DO NOTHING;
+ SQL
+ end
+ end
+ end
+end