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
1c71de07
Commit
1c71de07
authored
Oct 21, 2019
by
Jarka Košanová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate only AttachmentUploader note uploads
- keep uploads for other models as they are
parent
24c079de
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
6 deletions
+26
-6
lib/gitlab/background_migration/legacy_upload_mover.rb
lib/gitlab/background_migration/legacy_upload_mover.rb
+1
-0
lib/gitlab/background_migration/legacy_uploads_migrator.rb
lib/gitlab/background_migration/legacy_uploads_migrator.rb
+1
-1
lib/tasks/gitlab/uploads/legacy.rake
lib/tasks/gitlab/uploads/legacy.rake
+1
-1
spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb
...b/gitlab/background_migration/legacy_upload_mover_spec.rb
+13
-2
spec/lib/gitlab/background_migration/legacy_uploads_migrator_spec.rb
...tlab/background_migration/legacy_uploads_migrator_spec.rb
+10
-2
No files found.
lib/gitlab/background_migration/legacy_upload_mover.rb
View file @
1c71de07
...
...
@@ -18,6 +18,7 @@ module Gitlab
def
execute
return
unless
upload
return
unless
upload
.
model_type
==
'Note'
if
!
project
# if we don't have models associated with the upload we can not move it
...
...
lib/gitlab/background_migration/legacy_uploads_migrator.rb
View file @
1c71de07
...
...
@@ -14,7 +14,7 @@ module Gitlab
include
Database
::
MigrationHelpers
def
perform
(
start_id
,
end_id
)
Upload
.
where
(
id:
start_id
..
end_id
,
uploader:
'AttachmentUploader'
).
find_each
do
|
upload
|
Upload
.
where
(
id:
start_id
..
end_id
,
uploader:
'AttachmentUploader'
,
model_type:
'Note'
).
find_each
do
|
upload
|
LegacyUploadMover
.
new
(
upload
).
execute
end
end
...
...
lib/tasks/gitlab/uploads/legacy.rake
View file @
1c71de07
...
...
@@ -15,7 +15,7 @@ namespace :gitlab do
batch_size
=
5000
delay_interval
=
5
.
minutes
.
to_i
Upload
.
where
(
uploader:
'AttachmentUploader'
).
each_batch
(
of:
batch_size
)
do
|
relation
,
index
|
Upload
.
where
(
uploader:
'AttachmentUploader'
,
model_type:
'Note'
).
each_batch
(
of:
batch_size
)
do
|
relation
,
index
|
start_id
,
end_id
=
relation
.
pluck
(
'MIN(id), MAX(id)'
).
first
delay
=
index
*
delay_interval
...
...
spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb
View file @
1c71de07
...
...
@@ -91,15 +91,26 @@ describe Gitlab::BackgroundMigration::LegacyUploadMover do
end
end
context
'when no
model
found for the upload'
do
context
'when no
note
found for the upload'
do
before
do
legacy_upload
.
model
=
nil
legacy_upload
.
model_id
=
nil
legacy_upload
.
model_type
=
'Note'
expect_error_log
end
it_behaves_like
'legacy upload deletion'
end
context
'when upload does not belong to a note'
do
before
do
legacy_upload
.
model
=
create
(
:appearance
)
end
it
'does not remove the upload'
do
expect
{
described_class
.
new
(
legacy_upload
).
execute
}.
not_to
change
{
Upload
.
count
}
end
end
context
'when the upload move fails'
do
before
do
expect
(
FileUploader
).
to
receive
(
:copy_to
).
and_raise
(
'failed'
)
...
...
spec/lib/gitlab/background_migration/legacy_uploads_migrator_spec.rb
View file @
1c71de07
...
...
@@ -35,6 +35,8 @@ describe Gitlab::BackgroundMigration::LegacyUploadsMigrator do
let!
(
:legacy_upload_no_file
)
{
create_upload
(
note2
,
false
)
}
let!
(
:legacy_upload_legacy_project
)
{
create_upload
(
note_legacy
)
}
let!
(
:appearance
)
{
create
(
:appearance
,
:with_logo
)
}
let
(
:start_id
)
{
1
}
let
(
:end_id
)
{
10000
}
...
...
@@ -52,12 +54,18 @@ describe Gitlab::BackgroundMigration::LegacyUploadsMigrator do
expect
(
File
.
exist?
(
legacy_upload_legacy_project
.
absolute_path
)).
to
be_falsey
end
it
'removes all AttachmentUploader records'
do
expect
{
subject
}.
to
change
{
Upload
.
where
(
uploader:
'AttachmentUploader'
).
count
}.
from
(
3
).
to
(
0
)
it
'removes all
Note
AttachmentUploader records'
do
expect
{
subject
}.
to
change
{
Upload
.
where
(
uploader:
'AttachmentUploader'
).
count
}.
from
(
4
).
to
(
1
)
end
it
'creates new uploads for successfully migrated records'
do
expect
{
subject
}.
to
change
{
Upload
.
where
(
uploader:
'FileUploader'
).
count
}.
from
(
0
).
to
(
2
)
end
it
'does not remove appearance uploads'
do
subject
expect
(
appearance
.
logo
.
file
).
to
exist
end
end
# rubocop: enable RSpec/FactoriesInMigrationSpecs
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