Commit ba3f32c0 authored by Toon Claes's avatar Toon Claes

Save project_repository only for hashed storage

When a new project is created, or migrated to hashed storage,
create/update the project repository row.
parent de7d82d6
......@@ -120,7 +120,7 @@ class Project < ActiveRecord::Base
after_create :ensure_storage_path_exists
after_save :ensure_storage_path_exists, if: :namespace_id_changed?
after_create :create_project_repository
after_create :save_project_repository
acts_as_ordered_taggable
......@@ -1210,8 +1210,17 @@ class Project < ActiveRecord::Base
false
end
def create_project_repository
update(project_repository: ProjectRepository.create!(shard_name: repository_storage, disk_path: disk_path))
def save_project_repository
return unless hashed_storage?(:repository)
project_repo = project_repository || build_project_repository
project_repo.assign_attributes(shard_name: repository_storage, disk_path: disk_path)
if project_repo.persisted?
project_repo.save
else
update(project_repository: project_repo)
end
end
def create_repository(force: false)
......
......@@ -32,6 +32,7 @@ module Projects
if result
project.write_repository_config
project.create_project_repository
else
rollback_folder_move
project.storage_version = nil
......
......@@ -1730,16 +1730,28 @@ describe Project do
end
end
describe '#create_project_repository' do
describe '#save_project_repository' do
let(:project) { create(:project, :repository) }
it 'creates a project_repository' do
project.create_project_repository
project.save_project_repository
expect(project).to have_project_repository
expect(project.reload.project_repository).to be_present
expect(project.project_repository.disk_path).to eq(project.disk_path)
expect(project.project_repository.shard_name).to eq(project.repository_storage)
end
it 'updates the project_repository' do
project.save_project_repository
allow(project).to receive(:disk_path).and_return('@fancy/new/path')
expect do
project.save_project_repository
end.not_to change(ProjectRepository, :count)
expect(project.reload.project_repository.disk_path).to eq(project.disk_path)
end
end
describe '#create_repository' 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