diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 06:07:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 06:07:51 +0000 |
commit | 00bd11b166a886742f04d38c0d2551e52ff51472 (patch) | |
tree | af0b118c5748fdaabda2f9c2a007969c1673d581 /lib | |
parent | a0c1ba61c8e8c9195e3ad4deefc5c4cb5c6a1501 (diff) | |
download | gitlab-ce-00bd11b166a886742f04d38c0d2551e52ff51472.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/background_migration/link_lfs_objects.rb | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/lib/gitlab/background_migration/link_lfs_objects.rb b/lib/gitlab/background_migration/link_lfs_objects.rb index 69c03f617bf..3131b5d5125 100644 --- a/lib/gitlab/background_migration/link_lfs_objects.rb +++ b/lib/gitlab/background_migration/link_lfs_objects.rb @@ -6,6 +6,8 @@ module Gitlab class LinkLfsObjects # Model definition used for migration class ForkNetworkMember < ActiveRecord::Base + include EachBatch + self.table_name = 'fork_network_members' def self.with_non_existing_lfs_objects @@ -23,8 +25,62 @@ module Gitlab end end + # Model definition used for migration + class Project < ActiveRecord::Base + include EachBatch + + self.table_name = 'projects' + + has_one :fork_network_member, class_name: 'LinkLfsObjects::ForkNetworkMember' + + def self.with_non_existing_lfs_objects + fork_network_members = + ForkNetworkMember.with_non_existing_lfs_objects + .select(1) + .where('fork_network_members.project_id = projects.id') + + where('EXISTS (?)', fork_network_members) + end + end + + # Model definition used for migration + class LfsObjectsProject < ActiveRecord::Base + include EachBatch + + self.table_name = 'lfs_objects_projects' + end + + BATCH_SIZE = 1000 + def perform(start_id, end_id) - # no-op as some queries times out + forks = + Project + .with_non_existing_lfs_objects + .where(id: start_id..end_id) + + forks.includes(:fork_network_member).find_each do |project| + LfsObjectsProject + .select("lfs_objects_projects.lfs_object_id, #{project.id}, NOW(), NOW()") + .where(project_id: project.fork_network_member.forked_from_project_id) + .each_batch(of: BATCH_SIZE) do |batch| + execute <<~SQL + INSERT INTO lfs_objects_projects (lfs_object_id, project_id, created_at, updated_at) + #{batch.to_sql} + SQL + end + end + + logger.info(message: "LinkLfsObjects: created missing LfsObjectsProject for Projects #{forks.map(&:id).join(', ')}") + end + + private + + def execute(sql) + ::ActiveRecord::Base.connection.execute(sql) + end + + def logger + @logger ||= Gitlab::BackgroundMigration::Logger.build end end end |