diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 00:07:23 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-18 00:07:23 +0000 |
commit | 196f676f0e538e12501bc0ade8dd064c509230ba (patch) | |
tree | 024b06a803422eccad6a756ecf5d2357ed7ef0ba /db/fixtures | |
parent | 97db9c4644d04ca42b65240f218f803529ad5cf2 (diff) | |
download | gitlab-ce-196f676f0e538e12501bc0ade8dd064c509230ba.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db/fixtures')
-rw-r--r-- | db/fixtures/development/35_emails.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/db/fixtures/development/35_emails.rb b/db/fixtures/development/35_emails.rb new file mode 100644 index 00000000000..a743c326015 --- /dev/null +++ b/db/fixtures/development/35_emails.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +class Gitlab::Seeder::Emails + attr_reader :user, :group_namespace_ids, :project_namespace_ids + + def initialize(user, group_namespace_ids, project_namespace_ids) + @user = user + @group_namespace_ids = group_namespace_ids.sample(3) + @project_namespace_ids = project_namespace_ids.sample(3) + end + + def seed! + company_email = "#{user.username}-work@example.com" + personal_email = "#{user.username}-home@example.com" + oss_email = "#{user.username}-oss@example.com" + unverified_email = "#{user.username}-unverified@example.com" + + Email.create!( + user_id: user.id, + email: unverified_email + ) + + [company_email, personal_email, oss_email].each_with_index do |email, index| + email_id = Email.create!( + user_id: user.id, + email: email, + confirmed_at: DateTime.current + ).id + Users::NamespaceCommitEmail.create!( + user_id: user.id, + namespace_id: group_namespace_ids[index], + email_id: email_id + ) + Users::NamespaceCommitEmail.create!( + user_id: user.id, + namespace_id: project_namespace_ids[index], + email_id: email_id + ) + print '.' + end + end +end + +Gitlab::Seeder.quiet do + puts "\nGenerating email data" + + group_namespace_ids = Group.not_mass_generated.where('parent_id IS NULL').pluck(:id) + project_namespace_ids = Project.all.pluck(:project_namespace_id) + + User.first(3).each do |user| + Gitlab::Seeder::Emails.new(user, group_namespace_ids, project_namespace_ids).seed! + rescue => e + warn "\nError seeding e-mails: #{e}" + end +end |