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
1e46fd73
Commit
1e46fd73
authored
Jan 23, 2018
by
Micaël Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first iteration of the gitlab:uploads:migrate task
parent
e77fc3f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
2 deletions
+73
-2
app/models/upload.rb
app/models/upload.rb
+2
-2
lib/tasks/gitlab/uploads.rake
lib/tasks/gitlab/uploads.rake
+71
-0
No files found.
app/models/upload.rb
View file @
1e46fd73
...
...
@@ -36,8 +36,8 @@ class Upload < ActiveRecord::Base
self
.
checksum
=
self
.
class
.
hexdigest
(
absolute_path
)
end
def
build_uploader
uploader_class
.
new
(
model
,
mount
_point
,
**
uploader_contex
t
).
tap
do
|
uploader
|
def
build_uploader
(
mounted_as
=
nil
)
uploader_class
.
new
(
model
,
mount
ed_as
||
mount_poin
t
).
tap
do
|
uploader
|
uploader
.
upload
=
self
uploader
.
retrieve_from_store!
(
identifier
)
end
...
...
lib/tasks/gitlab/uploads.rake
View file @
1e46fd73
...
...
@@ -19,6 +19,77 @@ namespace :gitlab do
puts
'Done!'
end
desc
'GitLab | Uploads | Migrate the uploaded files to object storage'
task
:migrate
,
[
:uploader_class
,
:model_class
,
:mounted_as
]
=>
:environment
do
|
task
,
args
|
MIGRATE_TO_STORE
=
ObjectStorage
::
Store
::
REMOTE
class
MigrationResult
attr_reader
:upload
attr_accessor
:error
def
initialize
(
upload
,
error
=
nil
)
@upload
,
@error
=
upload
,
error
end
def
success?
error
.
nil?
end
def
to_s
success?
?
"Migration sucessful."
:
"Error while migrating
#{
upload
.
id
}
:
#{
error
.
message
}
"
end
end
uploader_class
=
args
.
uploader_class
.
constantize
model_class
=
args
.
model_class
.
constantize
mounted_as
=
args
.
mounted_as
&
.
gsub
(
':'
,
''
)
&
.
to_sym
global_results
=
[]
Upload
.
preload
(
:model
)
.
where
.
not
(
store:
MIGRATE_TO_STORE
)
.
where
(
uploader:
uploader_class
.
to_s
,
model_type:
model_class
.
to_s
)
.
in_batches
(
of:
batch_size
)
do
|
batch
|
results
=
migrate
(
build_uploaders
(
batch
,
mounted_as
))
report
(
results
)
global_results
.
concat
(
results
)
end
puts
"
\n
=== Migration summary ==="
report
(
global_results
)
end
def
report
(
results
)
results
=
results
.
group_by
(
&
:success?
)
success
,
errors
=
[
results
.
fetch
(
true
,
[]),
results
.
fetch
(
false
,
[])
]
batch_color
=
errors
.
count
==
0
?
:green
:
:red
puts
"Migrated
#{
success
.
count
}
/
#{
success
.
count
+
errors
.
count
}
files."
.
color
(
batch_color
)
errors
.
each
{
|
e
|
puts
(
"
\t
#{
e
}
"
).
color
(
:red
)
}
end
def
build_uploaders
(
uploads
,
mounted_as
)
uploads
.
map
{
|
upload
|
upload
.
build_uploader
(
mounted_as
)
}
end
def
migrate
(
uploaders
)
uploaders
.
map
do
|
uploader
|
result
=
MigrationResult
.
new
(
uploader
.
upload
)
begin
uploader
.
migrate!
(
MIGRATE_TO_STORE
)
result
rescue
CarrierWave
::
UploadError
=>
e
result
.
error
=
e
result
end
end
end
def
batch_size
ENV
.
fetch
(
'BATCH'
,
200
).
to_i
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