summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-10-09 12:33:35 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-10-09 12:33:35 +0000
commitf277fa14094e5515e2317d2baa1fa0bfb95966da (patch)
treeba7d392337ab6f82b6edb9724888e3002b69b223
parent781d2c22f411f492845f42b15863f4a0a5a5eaa6 (diff)
parent392e5df796166f0ebe04cca8f6301bcdc676543e (diff)
downloadgitlab-ce-f277fa14094e5515e2317d2baa1fa0bfb95966da.tar.gz
Merge branch 'bvl-fork-network-migrations' into 'master'
Create fork networks for root projects that are deleted Closes #38905 See merge request gitlab-org/gitlab-ce!14752
-rw-r--r--lib/gitlab/background_migration/create_fork_network_memberships_range.rb5
-rw-r--r--lib/gitlab/background_migration/populate_fork_networks_range.rb5
-rw-r--r--spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb8
3 files changed, 18 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/create_fork_network_memberships_range.rb b/lib/gitlab/background_migration/create_fork_network_memberships_range.rb
index 4b468e9cd58..c88eb9783ed 100644
--- a/lib/gitlab/background_migration/create_fork_network_memberships_range.rb
+++ b/lib/gitlab/background_migration/create_fork_network_memberships_range.rb
@@ -46,6 +46,11 @@ module Gitlab
FROM fork_network_members
WHERE fork_network_members.project_id = forked_project_links.forked_to_project_id
)
+ AND EXISTS (
+ SELECT true
+ FROM projects
+ WHERE forked_project_links.forked_from_project_id = projects.id
+ )
AND forked_project_links.id BETWEEN #{start_id} AND #{end_id}
MISSING_MEMBERS
diff --git a/lib/gitlab/background_migration/populate_fork_networks_range.rb b/lib/gitlab/background_migration/populate_fork_networks_range.rb
index 6c355ed1e75..2ef3a207dd3 100644
--- a/lib/gitlab/background_migration/populate_fork_networks_range.rb
+++ b/lib/gitlab/background_migration/populate_fork_networks_range.rb
@@ -20,6 +20,11 @@ module Gitlab
FROM fork_networks
WHERE forked_project_links.forked_from_project_id = fork_networks.root_project_id
)
+ AND EXISTS (
+ SELECT true
+ FROM projects
+ WHERE projects.id = forked_project_links.forked_from_project_id
+ )
AND forked_project_links.id BETWEEN #{start_id} AND #{end_id}
INSERT_NETWORKS
diff --git a/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb b/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb
index 3ef1873e615..2c2684a6fc9 100644
--- a/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb
+++ b/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb
@@ -62,6 +62,14 @@ describe Gitlab::BackgroundMigration::PopulateForkNetworksRange, :migration, sch
expect(base2_membership).not_to be_nil
end
+ it 'skips links that had their source project deleted' do
+ forked_project_links.create(id: 6, forked_from_project_id: 99999, forked_to_project_id: create(:project).id)
+
+ migration.perform(5, 8)
+
+ expect(fork_networks.find_by(root_project_id: 99999)).to be_nil
+ end
+
it 'schedules a job for inserting memberships for forks-of-forks' do
delay = Gitlab::BackgroundMigration::CreateForkNetworkMembershipsRange::RESCHEDULE_DELAY