Commit aaf18bb8 authored by Bob Van Landuyt's avatar Bob Van Landuyt 🔴

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.
parent 148f4079
Pipeline #13912907 passed with stages
in 78 minutes and 25 seconds
---
title: Don't try to create fork network memberships for forks with a missing source
merge_request: 15366
author:
type: fixed
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment