Commit 2a267e8c authored by Jan Provaznik's avatar Jan Provaznik
Browse files

Merge branch 'bvl-allow-moving-forked-projects-across-shards' into 'master'

Allow moving forked projects across shards

See merge request gitlab-org/gitlab!21339
parents 0b444ffb 9e952693
---
title: Fix forking a deduplicated project after it was moved to a different shard
merge_request: 21339
author:
type: fixed
# frozen_string_literal: true
class UpdateIndexForPoolRepositories < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
# This index is less restrictive then the one we already have, no need to
# update data.
add_concurrent_index :pool_repositories, [:source_project_id, :shard_id], unique: true
remove_concurrent_index :pool_repositories, :source_project_id
end
def down
# Not adding this index as a unique one, since while the new index existed
# we could have created multiple pool repositories for a project. In that
# case this rollback would fail.
add_concurrent_index :pool_repositories, :source_project_id
remove_concurrent_index :pool_repositories, [:source_project_id, :shard_id], unique: true
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
   
ActiveRecord::Schema.define(version: 2019_12_04_093410) do ActiveRecord::Schema.define(version: 2019_12_06_122926) do
   
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm" enable_extension "pg_trgm"
...@@ -2969,7 +2969,7 @@ ActiveRecord::Schema.define(version: 2019_12_04_093410) do ...@@ -2969,7 +2969,7 @@ ActiveRecord::Schema.define(version: 2019_12_04_093410) do
t.integer "source_project_id" t.integer "source_project_id"
t.index ["disk_path"], name: "index_pool_repositories_on_disk_path", unique: true t.index ["disk_path"], name: "index_pool_repositories_on_disk_path", unique: true
t.index ["shard_id"], name: "index_pool_repositories_on_shard_id" t.index ["shard_id"], name: "index_pool_repositories_on_shard_id"
t.index ["source_project_id"], name: "index_pool_repositories_on_source_project_id", unique: true t.index ["source_project_id", "shard_id"], name: "index_pool_repositories_on_source_project_id_and_shard_id", unique: true
end end
   
create_table "programming_languages", id: :serial, force: :cascade do |t| create_table "programming_languages", id: :serial, force: :cascade do |t|
......
# frozen_string_literal: true
require 'spec_helper'
# This spec lives in `ee/` since moving shards is an EE-only feature.
describe Projects::ForkService do
include ProjectForksHelper
context 'when a project is already forked' do
it 'creates a new poolresository after the project is moved to a new shard' do
project = create(:project, :public, :repository)
fork_before_move = fork_project(project)
# Stub everything required to move a project to a Gitaly shard that does not exist
allow(Gitlab.config.repositories.storages).to receive(:keys).and_return(%w(default test_second_storage))
allow_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror).and_return(true)
Projects::UpdateRepositoryStorageService.new(project).execute('test_second_storage')
fork_after_move = fork_project(project)
pool_repository_before_move = PoolRepository.joins(:shard)
.where(source_project: project, shards: { name: 'default' }).first
pool_repository_after_move = PoolRepository.joins(:shard)
.where(source_project: project, shards: { name: 'test_second_storage' }).first
expect(fork_before_move.pool_repository).to eq(pool_repository_before_move)
expect(fork_after_move.pool_repository).to eq(pool_repository_after_move)
end
end
end
Supports Markdown
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