summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-02-08 11:22:04 +0000
committerIan Baum <ibaum@gitlab.com>2018-02-12 11:19:41 -0600
commit23501137a6b15acd70fceda20267b8db1cde89b5 (patch)
treeea7430944ba4db4f7b71a7e3dacc67d3d3b56525 /lib
parent466d93d663519e02fbc8cd3ff4b66c97c73e94c5 (diff)
downloadgitlab-ce-23501137a6b15acd70fceda20267b8db1cde89b5.tar.gz
Merge branch 'bvl-fix-concurrent-fork-network-migrations' into 'master'
Fix concurrent fork network migrations Closes #41487 See merge request gitlab-org/gitlab-ce!16988
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/background_migration/create_fork_network_memberships_range.rb15
1 files changed, 11 insertions, 4 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 03b17b319fa..1b4a9e8a194 100644
--- a/lib/gitlab/background_migration/create_fork_network_memberships_range.rb
+++ b/lib/gitlab/background_migration/create_fork_network_memberships_range.rb
@@ -14,6 +14,14 @@ module Gitlab
def perform(start_id, end_id)
log("Creating memberships for forks: #{start_id} - #{end_id}")
+ insert_members(start_id, end_id)
+
+ if missing_members?(start_id, end_id)
+ BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, "CreateForkNetworkMembershipsRange", [start_id, end_id])
+ end
+ end
+
+ def insert_members(start_id, end_id)
ActiveRecord::Base.connection.execute <<~INSERT_MEMBERS
INSERT INTO fork_network_members (fork_network_id, project_id, forked_from_project_id)
@@ -33,10 +41,9 @@ module Gitlab
WHERE existing_members.project_id = forked_project_links.forked_to_project_id
)
INSERT_MEMBERS
-
- if missing_members?(start_id, end_id)
- BackgroundMigrationWorker.perform_in(RESCHEDULE_DELAY, "CreateForkNetworkMembershipsRange", [start_id, end_id])
- end
+ rescue ActiveRecord::RecordNotUnique => e
+ # `fork_network_member` was created concurrently in another migration
+ log(e.message)
end
def missing_members?(start_id, end_id)