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
4f24a65e
Commit
4f24a65e
authored
Mar 29, 2018
by
Micaël Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the rake task from being to strict about Group
parent
80ef79f2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
16 deletions
+116
-16
app/workers/object_storage/migrate_uploads_worker.rb
app/workers/object_storage/migrate_uploads_worker.rb
+7
-9
lib/tasks/gitlab/uploads/migrate.rake
lib/tasks/gitlab/uploads/migrate.rake
+1
-0
spec/tasks/gitlab/uploads/migrate_rake_spec.rb
spec/tasks/gitlab/uploads/migrate_rake_spec.rb
+108
-7
No files found.
app/workers/object_storage/migrate_uploads_worker.rb
View file @
4f24a65e
...
@@ -138,21 +138,18 @@ module ObjectStorage
...
@@ -138,21 +138,18 @@ module ObjectStorage
include
Report
include
Report
def
self
.
enqueue!
(
uploads
,
mounted_as
,
to_store
)
def
self
.
enqueue!
(
uploads
,
mo
del_class
,
mo
unted_as
,
to_store
)
sanity_check!
(
uploads
,
mounted_as
)
sanity_check!
(
uploads
,
mo
del_class
,
mo
unted_as
)
perform_async
(
uploads
.
ids
,
mounted_as
,
to_store
)
perform_async
(
uploads
.
ids
,
mo
del_class
.
to_s
,
mo
unted_as
,
to_store
)
end
end
# We need to be sure all the uploads are for the same uploader and model type
# We need to be sure all the uploads are for the same uploader and model type
# and that the mount point exists if provided.
# and that the mount point exists if provided.
#
#
def
self
.
sanity_check!
(
uploads
,
mounted_as
)
def
self
.
sanity_check!
(
uploads
,
mo
del_class
,
mo
unted_as
)
upload
=
uploads
.
first
upload
=
uploads
.
first
uploader_class
=
upload
.
uploader
.
constantize
uploader_class
=
upload
.
uploader
.
constantize
model_class
=
uploads
.
first
.
model_type
.
constantize
uploader_types
=
uploads
.
map
(
&
:uploader
).
uniq
uploader_types
=
uploads
.
map
(
&
:uploader
).
uniq
model_types
=
uploads
.
map
(
&
:model_type
).
uniq
model_types
=
uploads
.
map
(
&
:model_type
).
uniq
model_has_mount
=
mounted_as
.
nil?
||
model_class
.
uploaders
[
mounted_as
]
==
uploader_class
model_has_mount
=
mounted_as
.
nil?
||
model_class
.
uploaders
[
mounted_as
]
==
uploader_class
...
@@ -162,7 +159,8 @@ module ObjectStorage
...
@@ -162,7 +159,8 @@ module ObjectStorage
raise
(
SanityCheckError
,
"Mount point
#{
mounted_as
}
not found in
#{
model_class
}
."
)
unless
model_has_mount
raise
(
SanityCheckError
,
"Mount point
#{
mounted_as
}
not found in
#{
model_class
}
."
)
unless
model_has_mount
end
end
def
perform
(
ids
,
mounted_as
,
to_store
)
def
perform
(
ids
,
model_type
,
mounted_as
,
to_store
)
@model_class
=
model_type
.
constantize
@mounted_as
=
mounted_as
&
.
to_sym
@mounted_as
=
mounted_as
&
.
to_sym
@to_store
=
to_store
@to_store
=
to_store
...
@@ -178,7 +176,7 @@ module ObjectStorage
...
@@ -178,7 +176,7 @@ module ObjectStorage
end
end
def
sanity_check!
(
uploads
)
def
sanity_check!
(
uploads
)
self
.
class
.
sanity_check!
(
uploads
,
@mounted_as
)
self
.
class
.
sanity_check!
(
uploads
,
@mo
del_class
,
@mo
unted_as
)
end
end
def
build_uploaders
(
uploads
)
def
build_uploaders
(
uploads
)
...
...
lib/tasks/gitlab/uploads/migrate.rake
View file @
4f24a65e
...
@@ -13,6 +13,7 @@ namespace :gitlab do
...
@@ -13,6 +13,7 @@ namespace :gitlab do
def
enqueue_batch
(
batch
,
index
)
def
enqueue_batch
(
batch
,
index
)
job
=
ObjectStorage
::
MigrateUploadsWorker
.
enqueue!
(
batch
,
job
=
ObjectStorage
::
MigrateUploadsWorker
.
enqueue!
(
batch
,
@model_class
,
@mounted_as
,
@mounted_as
,
@to_store
)
@to_store
)
puts
"Enqueued job #
#{
index
}
:
#{
job
}
"
puts
"Enqueued job #
#{
index
}
:
#{
job
}
"
...
...
spec/tasks/gitlab/uploads/migrate_rake_spec.rb
View file @
4f24a65e
require
'rake_helper'
require
'rake_helper'
describe
'gitlab:uploads:migrate rake tasks'
do
describe
'gitlab:uploads:migrate rake tasks'
do
let!
(
:projects
)
{
create_list
(
:project
,
10
,
:with_avatar
)
}
let
(
:model_class
)
{
nil
}
let
(
:model_class
)
{
Project
}
let
(
:uploader_class
)
{
nil
}
let
(
:uploader_class
)
{
AvatarUploader
}
let
(
:mounted_as
)
{
nil
}
let
(
:mounted_as
)
{
:avatar
}
let
(
:batch_size
)
{
3
}
let
(
:batch_size
)
{
3
}
before
do
before
do
...
@@ -30,6 +29,14 @@ describe 'gitlab:uploads:migrate rake tasks' do
...
@@ -30,6 +29,14 @@ describe 'gitlab:uploads:migrate rake tasks' do
end
end
end
end
context
"for AvatarUploader"
do
let
(
:uploader_class
)
{
AvatarUploader
}
let
(
:mounted_as
)
{
:avatar
}
context
"for Project"
do
let
(
:model_class
)
{
Project
}
let!
(
:projects
)
{
create_list
(
:project
,
10
,
:with_avatar
)
}
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
context
'Upload has store = nil'
do
context
'Upload has store = nil'
do
...
@@ -37,6 +44,100 @@ describe 'gitlab:uploads:migrate rake tasks' do
...
@@ -37,6 +44,100 @@ describe 'gitlab:uploads:migrate rake tasks' do
Upload
.
where
(
model:
projects
).
update_all
(
store:
nil
)
Upload
.
where
(
model:
projects
).
update_all
(
store:
nil
)
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
end
context
"for Group"
do
let
(
:model_class
)
{
Group
}
before
do
create_list
(
:group
,
10
,
:with_avatar
)
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for User"
do
let
(
:model_class
)
{
User
}
before
do
create_list
(
:user
,
10
,
:with_avatar
)
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
end
context
"for AttachmentUploader"
do
let
(
:uploader_class
)
{
AttachmentUploader
}
context
"for Note"
do
let
(
:model_class
)
{
Note
}
let
(
:mounted_as
)
{
:attachment
}
before
do
create_list
(
:note
,
10
,
:with_attachment
)
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for Appearance"
do
let
(
:model_class
)
{
Appearance
}
let
(
:mounted_as
)
{
:logo
}
before
do
create
(
:appearance
,
:with_logos
)
end
%i(logo header_logo)
.
each
do
|
mount
|
it_behaves_like
'enqueue jobs in batch'
,
batch:
1
do
let
(
:mounted_as
)
{
mount
}
end
end
end
end
context
"for FileUploader"
do
let
(
:uploader_class
)
{
FileUploader
}
let
(
:model_class
)
{
Project
}
before
do
create_list
(
:project
,
10
)
do
|
model
|
uploader_class
.
new
(
model
)
.
store!
(
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
))
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for PersonalFileUploader"
do
let
(
:uploader_class
)
{
PersonalFileUploader
}
let
(
:model_class
)
{
PersonalSnippet
}
before
do
create_list
(
:personal_snippet
,
10
)
do
|
model
|
uploader_class
.
new
(
model
)
.
store!
(
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
))
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
context
"for NamespaceFileUploader"
do
let
(
:uploader_class
)
{
NamespaceFileUploader
}
let
(
:model_class
)
{
Snippet
}
before
do
create_list
(
:snippet
,
10
)
do
|
model
|
uploader_class
.
new
(
model
)
.
store!
(
fixture_file_upload
(
'spec/fixtures/doc_sample.txt'
))
end
end
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
it_behaves_like
'enqueue jobs in batch'
,
batch:
4
end
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