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
This commit is contained in:
Yorick Peterse 2017-10-09 12:33:35 +00:00
commit f277fa1409
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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