diff options
author | Michael Kozono <mkozono@gmail.com> | 2019-02-21 10:18:54 -0800 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2019-02-21 10:18:54 -0800 |
commit | 7e9eda100a3ee13df1fa4f1cc04de73166ad1df9 (patch) | |
tree | 879bd1cbb2e9090ccc58dadd732e3116ef02c534 | |
parent | 99e363debddbc75e1bc401dcecd41ea748b001e0 (diff) | |
download | gitlab-ce-mk/seed-projects-rake-task.tar.gz |
Add dev rake task for seeding lots of projectsmk/seed-projects-rake-task
-rw-r--r-- | lib/tasks/dev.rake | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 4beb94eeb8e..6d3e181744c 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -12,4 +12,41 @@ namespace :dev do task load: :environment do Rails.application.eager_load! end + + desc "GitLab | Create many test groups and projects" + task :populate, [:username, :prefix, :group_start, :group_end, :projects_per_group] => :environment do |task, args| + user = User.find_by!(username: args.username || "root") + prefix = args.prefix || "test-1" + group_start = (args.group_start || 1).to_i + group_end = (args.group_end || 5).to_i + projects_per_group = (args.projects_per_group || 100).to_i + + ActiveRecord::Base.logger = nil + + group_start.upto(group_end).each do |gid| + group_name = "#{prefix}-group-#{gid}" + + ActiveRecord::Base.transaction do + group = Group.create!(path: group_name, name: group_name, owner: user) + print "Group #{gid}: " + + 1.upto(projects_per_group).each do |pid| + project_name = "project-#{pid}" + + project = Projects::CreateService.new( + user, + name: project_name, path: project_name, namespace_id: group.id + ).execute + + if project.errors.any? + raise "Failed: #{gid}.#{pid}:\n\t#{project.errors.full_messages.join("\n\t")}" + end + + print "." if pid%10==0 + end + + print "\n" + end + end + end end |