Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e11196f8
Commit
e11196f8
authored
Oct 16, 2020
by
James Fargher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow automatically selecting repository storage on move
This uses the same storage weights as projects do on creation.
parent
91bf399d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
5 deletions
+38
-5
app/models/project_repository_storage_move.rb
app/models/project_repository_storage_move.rb
+10
-0
changelogs/unreleased/automatic_move_storage.yml
changelogs/unreleased/automatic_move_storage.yml
+5
-0
doc/api/project_repository_storage_moves.md
doc/api/project_repository_storage_moves.md
+1
-1
lib/api/project_repository_storage_moves.rb
lib/api/project_repository_storage_moves.rb
+1
-1
spec/factories/project_repository_storage_moves.rb
spec/factories/project_repository_storage_moves.rb
+0
-1
spec/models/project_repository_storage_move_spec.rb
spec/models/project_repository_storage_move_spec.rb
+12
-0
spec/requests/api/project_repository_storage_moves_spec.rb
spec/requests/api/project_repository_storage_moves_spec.rb
+9
-2
No files found.
app/models/project_repository_storage_move.rb
View file @
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
...
...
changelogs/unreleased/automatic_move_storage.yml
0 → 100644
View file @
e11196f8
---
title
:
Allow automatically selecting repository storage on move
merge_request
:
45338
author
:
type
:
changed
doc/api/project_repository_storage_moves.md
View file @
e11196f8
...
...
@@ -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:
...
...
lib/api/project_repository_storage_moves.rb
View file @
e11196f8
...
...
@@ -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
(
...
...
spec/factories/project_repository_storage_moves.rb
View file @
e11196f8
...
...
@@ -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
}
...
...
spec/models/project_repository_storage_move_spec.rb
View file @
e11196f8
...
...
@@ -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
)
}
...
...
spec/requests/api/project_repository_storage_moves_spec.rb
View file @
e11196f8
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment