diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-08 18:16:04 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-10-09 08:44:23 +0200 |
commit | 392e5df796166f0ebe04cca8f6301bcdc676543e (patch) | |
tree | c3f6d2a995c28ca81dd1639d70619a9bb83d277b | |
parent | 91f1d652f5a0ab82784fed6d81501d03113d2cd7 (diff) | |
download | gitlab-ce-bvl-fork-network-migrations.tar.gz |
Don't create fork networks for root projects that are deletedbvl-fork-network-migrations
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 |