diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /db/fixtures/development/03_project_4_routes.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'db/fixtures/development/03_project_4_routes.rb')
-rw-r--r-- | db/fixtures/development/03_project_4_routes.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/db/fixtures/development/03_project_4_routes.rb b/db/fixtures/development/03_project_4_routes.rb new file mode 100644 index 00000000000..3340849a733 --- /dev/null +++ b/db/fixtures/development/03_project_4_routes.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class Gitlab::Seeder::ProjectRoutes + include ActionView::Helpers::NumberHelper + + BATCH_SIZE = 100_000 + + def seed! + create_project_routes! + end + + def create_project_routes! + Gitlab::Seeder.with_mass_insert(Project.count, "Project routes") do + Project.each_batch(of: BATCH_SIZE / 2) do |batch, index| + range = batch.pluck(Arel.sql('MIN(id)'), Arel.sql('MAX(id)')).first + count = index * batch.size + + Gitlab::Seeder.log_message("Creating project routes: #{count}.") + ActiveRecord::Base.connection.execute <<~SQL + INSERT INTO routes (namespace_id, source_id, source_type, name, path) + SELECT + p.project_namespace_id as namespace_id, + p.id as source_id, + 'Project', + routes.name || ' / ' || p.name, + routes.path || '/' || p.path + FROM projects p + INNER JOIN routes ON routes.source_id = p.namespace_id and source_type = 'Namespace' + WHERE p.id BETWEEN #{range.first} AND #{range.last} + ON CONFLICT DO NOTHING; + SQL + end + end + end +end + +Gitlab::Seeder.quiet do + projects = Gitlab::Seeder::ProjectRoutes.new + projects.seed! +end |