Commit eff188a5 authored by Alper Akgun's avatar Alper Akgun

Merge branch 'automatic_move_storage' into 'master'

Allow automatically selecting repository storage on move

See merge request gitlab-org/gitlab!45338
parents b0c29c8f e11196f8
......@@ -20,6 +20,10 @@ class ProjectRepositoryStorageMove < ApplicationRecord
inclusion: { in: ->(_) { Gitlab.config.repositories.storages.keys } }
validate :project_repository_writable, on: :create
default_value_for(:destination_storage_name, allows_nil: false) do
pick_repository_storage
end
state_machine initial: :initial do
event :schedule do
transition initial: :scheduled
......@@ -77,6 +81,12 @@ class ProjectRepositoryStorageMove < ApplicationRecord
scope :order_created_at_desc, -> { order(created_at: :desc) }
scope :with_projects, -> { includes(project: :route) }
class << self
def pick_repository_storage
Project.pick_repository_storage
end
end
private
def project_repository_writable
......
---
title: Allow automatically selecting repository storage on move
merge_request: 45338
author:
type: changed
......@@ -194,7 +194,7 @@ Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `project_id` | integer | yes | ID of the project |
| `destination_storage_name` | string | yes | Name of the destination storage shard |
| `destination_storage_name` | string | no | Name of the destination storage shard. If not provided the storage will be selected automatically. |
Example request:
......
......@@ -69,7 +69,7 @@ module API
success Entities::ProjectRepositoryStorageMove
end
params do
requires :destination_storage_name, type: String, desc: 'The destination storage shard'
optional :destination_storage_name, type: String, desc: 'The destination storage shard'
end
post ':id/repository_storage_moves' do
storage_move = user_project.repository_storage_moves.build(
......
......@@ -5,7 +5,6 @@ FactoryBot.define do
project
source_storage_name { 'default' }
destination_storage_name { 'default' }
trait :scheduled do
state { ProjectRepositoryStorageMove.state_machines[:state].states[:scheduled].value }
......
......@@ -43,6 +43,18 @@ RSpec.describe ProjectRepositoryStorageMove, type: :model do
end
end
describe 'defaults' do
context 'destination_storage_name' do
subject { build(:project_repository_storage_move) }
it 'picks storage from ApplicationSetting' do
expect(Gitlab::CurrentSettings).to receive(:pick_repository_storage).and_return('picked').at_least(:once)
expect(subject.destination_storage_name).to eq('picked')
end
end
end
describe 'state transitions' do
let(:project) { create(:project) }
......
......@@ -145,10 +145,17 @@ RSpec.describe API::ProjectRepositoryStorageMoves do
context 'destination_storage_name is missing' do
let(:destination_storage_name) { nil }
it 'returns a validation error' do
it 'schedules a project repository storage move' do
create_project_repository_storage_move
expect(response).to have_gitlab_http_status(:bad_request)
storage_move = project.repository_storage_moves.last
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/project_repository_storage_move')
expect(json_response['id']).to eq(storage_move.id)
expect(json_response['state']).to eq('scheduled')
expect(json_response['source_storage_name']).to eq('default')
expect(json_response['destination_storage_name']).to be_present
end
end
end
......
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