Don't try to create fork network memberships for forks of forks

In case the root project of a Fork-of-fork is deleted, the ForkNetwork
and the membership for that fork network is never created. In this
case we shouldn't try to create the membership, since the parent
membership will never be created.

This means that these fork networks will be lost.
This commit is contained in:
Bob Van Landuyt 2017-11-14 10:33:20 +01:00
parent 148f40792c
commit aaf18bb8c8
3 changed files with 24 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
title: Don't try to create fork network memberships for forks with a missing source
merge_request: 15366
author:
type: fixed

View File

@ -51,10 +51,20 @@ module Gitlab
FROM projects
WHERE forked_project_links.forked_from_project_id = projects.id
)
AND NOT EXISTS (
SELECT true
FROM forked_project_links AS parent_links
WHERE parent_links.forked_to_project_id = forked_project_links.forked_from_project_id
AND NOT EXISTS (
SELECT true
FROM projects
WHERE parent_links.forked_from_project_id = projects.id
)
)
AND forked_project_links.id BETWEEN #{start_id} AND #{end_id}
MISSING_MEMBERS
ForkNetworkMember.count_by_sql(count_sql) > 0
ForkedProjectLink.count_by_sql(count_sql) > 0
end
def log(message)

View File

@ -93,7 +93,14 @@ describe Gitlab::BackgroundMigration::CreateForkNetworkMembershipsRange, :migrat
end
it 'knows it is finished for this range' do
expect(migration.missing_members?(1, 7)).to be_falsy
expect(migration.missing_members?(1, 8)).to be_falsy
end
it 'does not miss members for forks of forks for which the root was deleted' do
forked_project_links.create(id: 9, forked_from_project_id: base1_fork1.id, forked_to_project_id: create(:project).id)
base1.destroy
expect(migration.missing_members?(7, 10)).to be_falsy
end
context 'with more forks' do