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 ...@@ -20,6 +20,10 @@ class ProjectRepositoryStorageMove < ApplicationRecord
inclusion: { in: ->(_) { Gitlab.config.repositories.storages.keys } } inclusion: { in: ->(_) { Gitlab.config.repositories.storages.keys } }
validate :project_repository_writable, on: :create 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 state_machine initial: :initial do
event :schedule do event :schedule do
transition initial: :scheduled transition initial: :scheduled
...@@ -77,6 +81,12 @@ class ProjectRepositoryStorageMove < ApplicationRecord ...@@ -77,6 +81,12 @@ class ProjectRepositoryStorageMove < ApplicationRecord
scope :order_created_at_desc, -> { order(created_at: :desc) } scope :order_created_at_desc, -> { order(created_at: :desc) }
scope :with_projects, -> { includes(project: :route) } scope :with_projects, -> { includes(project: :route) }
class << self
def pick_repository_storage
Project.pick_repository_storage
end
end
private private
def project_repository_writable def project_repository_writable
......
---
title: Allow automatically selecting repository storage on move
merge_request: 45338
author:
type: changed
...@@ -194,7 +194,7 @@ Parameters: ...@@ -194,7 +194,7 @@ Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `project_id` | integer | yes | ID of the project | | `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: Example request:
......
...@@ -69,7 +69,7 @@ module API ...@@ -69,7 +69,7 @@ module API
success Entities::ProjectRepositoryStorageMove success Entities::ProjectRepositoryStorageMove
end end
params do 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 end
post ':id/repository_storage_moves' do post ':id/repository_storage_moves' do
storage_move = user_project.repository_storage_moves.build( storage_move = user_project.repository_storage_moves.build(
......
...@@ -5,7 +5,6 @@ FactoryBot.define do ...@@ -5,7 +5,6 @@ FactoryBot.define do
project project
source_storage_name { 'default' } source_storage_name { 'default' }
destination_storage_name { 'default' }
trait :scheduled do trait :scheduled do
state { ProjectRepositoryStorageMove.state_machines[:state].states[:scheduled].value } state { ProjectRepositoryStorageMove.state_machines[:state].states[:scheduled].value }
......
...@@ -43,6 +43,18 @@ RSpec.describe ProjectRepositoryStorageMove, type: :model do ...@@ -43,6 +43,18 @@ RSpec.describe ProjectRepositoryStorageMove, type: :model do
end end
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 describe 'state transitions' do
let(:project) { create(:project) } let(:project) { create(:project) }
......
...@@ -145,10 +145,17 @@ RSpec.describe API::ProjectRepositoryStorageMoves do ...@@ -145,10 +145,17 @@ RSpec.describe API::ProjectRepositoryStorageMoves do
context 'destination_storage_name is missing' do context 'destination_storage_name is missing' do
let(:destination_storage_name) { nil } let(:destination_storage_name) { nil }
it 'returns a validation error' do it 'schedules a project repository storage move' do
create_project_repository_storage_move 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 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