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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
a210cb6b
Commit
a210cb6b
authored
Nov 09, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename table to untracked_files_for_uploads
parent
2ab3031b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
157 additions
and
157 deletions
+157
-157
db/post_migrate/20171103140253_track_untracked_uploads.rb
db/post_migrate/20171103140253_track_untracked_uploads.rb
+9
-9
db/schema.rb
db/schema.rb
+3
-3
lib/gitlab/background_migration/populate_untracked_uploads.rb
...gitlab/background_migration/populate_untracked_uploads.rb
+8
-8
lib/gitlab/background_migration/prepare_untracked_uploads.rb
lib/gitlab/background_migration/prepare_untracked_uploads.rb
+11
-11
spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
...b/background_migration/populate_untracked_uploads_spec.rb
+106
-106
spec/lib/gitlab/background_migration/prepare_untracked_uploads_spec.rb
...ab/background_migration/prepare_untracked_uploads_spec.rb
+12
-12
spec/migrations/track_untracked_uploads_spec.rb
spec/migrations/track_untracked_uploads_spec.rb
+8
-8
No files found.
db/post_migrate/20171103140253_track_untracked_uploads.rb
View file @
a210cb6b
...
...
@@ -7,31 +7,31 @@ class TrackUntrackedUploads < ActiveRecord::Migration
disable_ddl_transaction!
DOWNTIME
=
false
MIGRATION
=
'PrepareUn
hash
edUploads'
MIGRATION
=
'PrepareUn
track
edUploads'
def
up
unless
table_exists?
(
:un
hashed_upload_file
s
)
create_table
:un
hashed_upload_file
s
do
|
t
|
unless
table_exists?
(
:un
tracked_files_for_upload
s
)
create_table
:un
tracked_files_for_upload
s
do
|
t
|
t
.
string
:path
,
null:
false
t
.
boolean
:tracked
,
default:
false
,
null:
false
t
.
timestamps_with_timezone
null:
false
end
end
unless
index_exists?
(
:un
hashed_upload_file
s
,
:path
)
add_index
:un
hashed_upload_file
s
,
:path
,
unique:
true
unless
index_exists?
(
:un
tracked_files_for_upload
s
,
:path
)
add_index
:un
tracked_files_for_upload
s
,
:path
,
unique:
true
end
unless
index_exists?
(
:un
hashed_upload_file
s
,
:tracked
)
add_index
:un
hashed_upload_file
s
,
:tracked
unless
index_exists?
(
:un
tracked_files_for_upload
s
,
:tracked
)
add_index
:un
tracked_files_for_upload
s
,
:tracked
end
BackgroundMigrationWorker
.
perform_async
(
MIGRATION
)
end
def
down
if
table_exists?
(
:un
hashed_upload_file
s
)
drop_table
:un
hashed_upload_file
s
if
table_exists?
(
:un
tracked_files_for_upload
s
)
drop_table
:un
tracked_files_for_upload
s
end
end
end
db/schema.rb
View file @
a210cb6b
...
...
@@ -1719,15 +1719,15 @@ ActiveRecord::Schema.define(version: 20171124150326) do
add_index
"u2f_registrations"
,
[
"key_handle"
],
name:
"index_u2f_registrations_on_key_handle"
,
using: :btree
add_index
"u2f_registrations"
,
[
"user_id"
],
name:
"index_u2f_registrations_on_user_id"
,
using: :btree
create_table
"un
hashed_upload_file
s"
,
force: :cascade
do
|
t
|
create_table
"un
tracked_files_for_upload
s"
,
force: :cascade
do
|
t
|
t
.
string
"path"
,
null:
false
t
.
boolean
"tracked"
,
default:
false
,
null:
false
t
.
datetime_with_timezone
"created_at"
,
null:
false
t
.
datetime_with_timezone
"updated_at"
,
null:
false
end
add_index
"un
hashed_upload_files"
,
[
"path"
],
name:
"index_unhashed_upload_file
s_on_path"
,
unique:
true
,
using: :btree
add_index
"un
hashed_upload_files"
,
[
"tracked"
],
name:
"index_unhashed_upload_file
s_on_tracked"
,
using: :btree
add_index
"un
tracked_files_for_uploads"
,
[
"path"
],
name:
"index_untracked_files_for_upload
s_on_path"
,
unique:
true
,
using: :btree
add_index
"un
tracked_files_for_uploads"
,
[
"tracked"
],
name:
"index_untracked_files_for_upload
s_on_tracked"
,
using: :btree
create_table
"uploads"
,
force: :cascade
do
|
t
|
t
.
integer
"size"
,
limit:
8
,
null:
false
...
...
lib/gitlab/background_migration/populate_untracked_uploads.rb
View file @
a210cb6b
module
Gitlab
module
BackgroundMigration
class
PopulateUntrackedUploads
class
Un
hashedUploa
dFile
<
ActiveRecord
::
Base
self
.
table_name
=
'un
hashed_upload_file
s'
class
Un
tracke
dFile
<
ActiveRecord
::
Base
self
.
table_name
=
'un
tracked_files_for_upload
s'
# Ends with /:random_hex/:filename
FILE_UPLOADER_PATH_PATTERN
=
%r{/
\h
+/[^/]+
\z
}
...
...
@@ -84,7 +84,7 @@ module Gitlab
end
def
upload_path
# Un
hashedUploa
dFile#path is absolute, but Upload#path depends on uploader
# Un
tracke
dFile#path is absolute, but Upload#path depends on uploader
if
uploader
==
'FileUploader'
# Path relative to project directory in uploads
matchd
=
path_relative_to_upload_dir
.
match
(
FILE_UPLOADER_PATH_PATTERN
)
...
...
@@ -118,7 +118,7 @@ module Gitlab
# Not including a leading slash
def
path_relative_to_upload_dir
base
=
%r{
\A
#{
Regexp
.
escape
(
Gitlab
::
BackgroundMigration
::
PrepareUn
hash
edUploads
::
UPLOAD_DIR
)
}
/}
base
=
%r{
\A
#{
Regexp
.
escape
(
Gitlab
::
BackgroundMigration
::
PrepareUn
track
edUploads
::
UPLOAD_DIR
)
}
/}
@path_relative_to_upload_dir
||=
path
.
sub
(
base
,
''
)
end
...
...
@@ -218,10 +218,10 @@ module Gitlab
def
perform
(
start_id
,
end_id
)
return
unless
migrate?
files
=
Un
hashedUploa
dFile
.
untracked
.
where
(
id:
start_id
..
end_id
)
files
.
each
do
|
un
hashed_uploa
d_file
|
files
=
Un
tracke
dFile
.
untracked
.
where
(
id:
start_id
..
end_id
)
files
.
each
do
|
un
tracke
d_file
|
begin
un
hashed_uploa
d_file
.
ensure_tracked!
un
tracke
d_file
.
ensure_tracked!
rescue
StandardError
=>
e
Rails
.
logger
.
warn
"Failed to add untracked file to uploads:
#{
e
.
message
}
"
...
...
@@ -235,7 +235,7 @@ module Gitlab
private
def
migrate?
Un
hashedUploa
dFile
.
table_exists?
&&
Upload
.
table_exists?
Un
tracke
dFile
.
table_exists?
&&
Upload
.
table_exists?
end
end
end
...
...
lib/gitlab/background_migration/prepare_un
hash
ed_uploads.rb
→
lib/gitlab/background_migration/prepare_un
track
ed_uploads.rb
View file @
a210cb6b
module
Gitlab
module
BackgroundMigration
class
PrepareUn
hash
edUploads
class
PrepareUn
track
edUploads
# For bulk_queue_background_migration_jobs_by_range
include
Database
::
MigrationHelpers
...
...
@@ -8,31 +8,31 @@ module Gitlab
UPLOAD_DIR
=
"
#{
CarrierWave
.
root
}
/uploads"
.
freeze
FOLLOW_UP_MIGRATION
=
'PopulateUntrackedUploads'
.
freeze
class
Un
hashedUploa
dFile
<
ActiveRecord
::
Base
class
Un
tracke
dFile
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'un
hashed_upload_file
s'
self
.
table_name
=
'un
tracked_files_for_upload
s'
end
def
perform
return
unless
migrate?
clear_un
hashed_uploa
d_file_paths
store_un
hashed_uploa
d_file_paths
clear_un
tracke
d_file_paths
store_un
tracke
d_file_paths
schedule_populate_untracked_uploads_jobs
end
private
def
migrate?
Un
hashedUploa
dFile
.
table_exists?
Un
tracke
dFile
.
table_exists?
end
def
clear_un
hashed_uploa
d_file_paths
Un
hashedUploa
dFile
.
delete_all
def
clear_un
tracke
d_file_paths
Un
tracke
dFile
.
delete_all
end
def
store_un
hashed_uploa
d_file_paths
def
store_un
tracke
d_file_paths
return
unless
Dir
.
exist?
(
UPLOAD_DIR
)
each_file_batch
(
UPLOAD_DIR
,
FILE_PATH_BATCH_SIZE
)
do
|
file_paths
|
...
...
@@ -89,7 +89,7 @@ module Gitlab
end
def
insert_file_path
(
file_path
)
table_columns_and_values
=
'un
hashed_upload_file
s (path, created_at, updated_at) VALUES (?, ?, ?)'
table_columns_and_values
=
'un
tracked_files_for_upload
s (path, created_at, updated_at) VALUES (?, ?, ?)'
sql
=
if
Gitlab
::
Database
.
postgresql?
"INSERT INTO
#{
table_columns_and_values
}
ON CONFLICT DO NOTHING;"
...
...
@@ -103,7 +103,7 @@ module Gitlab
end
def
schedule_populate_untracked_uploads_jobs
bulk_queue_background_migration_jobs_by_range
(
Un
hashedUploa
dFile
,
FOLLOW_UP_MIGRATION
)
bulk_queue_background_migration_jobs_by_range
(
Un
tracke
dFile
,
FOLLOW_UP_MIGRATION
)
end
end
end
...
...
spec/lib/gitlab/background_migration/populate_untracked_uploads_spec.rb
View file @
a210cb6b
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
PopulateUntrackedUploads
,
:migration
,
:sidekiq
,
schema:
20171103140253
do
let!
(
:un
hashed_upload_files
)
{
table
(
:unhashed_upload_file
s
)
}
let!
(
:un
tracked_files_for_uploads
)
{
table
(
:untracked_files_for_upload
s
)
}
let!
(
:uploads
)
{
table
(
:uploads
)
}
let
(
:user1
)
{
create
(
:user
)
}
...
...
@@ -10,7 +10,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
let
(
:project2
)
{
create
(
:project
)
}
let
(
:appearance
)
{
create
(
:appearance
)
}
context
'with untracked files and tracked files in un
hashed_upload_file
s'
do
context
'with untracked files and tracked files in un
tracked_files_for_upload
s'
do
before
do
fixture
=
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'rails_sample.jpg'
)
...
...
@@ -28,15 +28,15 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
UploadService
.
new
(
project2
,
uploaded_file
,
FileUploader
).
execute
# Markdown upload
appearance
.
update!
(
header_logo:
uploaded_file
)
#
Unhashed upload files created by PrepareUnhash
edUploads
un
hashed_upload_file
s
.
create!
(
path:
appearance
.
logo
.
file
.
file
)
un
hashed_upload_file
s
.
create!
(
path:
appearance
.
header_logo
.
file
.
file
)
un
hashed_upload_file
s
.
create!
(
path:
user1
.
avatar
.
file
.
file
)
un
hashed_upload_file
s
.
create!
(
path:
user2
.
avatar
.
file
.
file
)
un
hashed_upload_file
s
.
create!
(
path:
project1
.
avatar
.
file
.
file
)
un
hashed_upload_file
s
.
create!
(
path:
project2
.
avatar
.
file
.
file
)
un
hashed_upload_files
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
project1
.
full_path
}
/
#{
project1
.
uploads
.
last
.
path
}
"
)
un
hashed_upload_files
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
project2
.
full_path
}
/
#{
project2
.
uploads
.
last
.
path
}
"
)
#
File records created by PrepareUntrack
edUploads
un
tracked_files_for_upload
s
.
create!
(
path:
appearance
.
logo
.
file
.
file
)
un
tracked_files_for_upload
s
.
create!
(
path:
appearance
.
header_logo
.
file
.
file
)
un
tracked_files_for_upload
s
.
create!
(
path:
user1
.
avatar
.
file
.
file
)
un
tracked_files_for_upload
s
.
create!
(
path:
user2
.
avatar
.
file
.
file
)
un
tracked_files_for_upload
s
.
create!
(
path:
project1
.
avatar
.
file
.
file
)
un
tracked_files_for_upload
s
.
create!
(
path:
project2
.
avatar
.
file
.
file
)
un
tracked_files_for_uploads
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
project1
.
full_path
}
/
#{
project1
.
uploads
.
last
.
path
}
"
)
un
tracked_files_for_uploads
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
project2
.
full_path
}
/
#{
project2
.
uploads
.
last
.
path
}
"
)
user2
.
uploads
.
delete_all
project2
.
uploads
.
delete_all
...
...
@@ -56,7 +56,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
it
'sets all added or confirmed tracked files to tracked'
do
expect
do
described_class
.
new
.
perform
(
1
,
1000
)
end
.
to
change
{
un
hashed_upload_file
s
.
where
(
tracked:
true
).
count
}.
from
(
0
).
to
(
8
)
end
.
to
change
{
un
tracked_files_for_upload
s
.
where
(
tracked:
true
).
count
}.
from
(
0
).
to
(
8
)
end
it
'does not create duplicate uploads of already tracked files'
do
...
...
@@ -68,8 +68,8 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
end
it
'uses the start and end batch ids [only 1st half]'
do
start_id
=
un
hashed_upload_file
s
.
all
.
to_a
[
0
].
id
end_id
=
un
hashed_upload_file
s
.
all
.
to_a
[
3
].
id
start_id
=
un
tracked_files_for_upload
s
.
all
.
to_a
[
0
].
id
end_id
=
un
tracked_files_for_upload
s
.
all
.
to_a
[
3
].
id
expect
do
described_class
.
new
.
perform
(
start_id
,
end_id
)
...
...
@@ -82,12 +82,12 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
expect
(
project2
.
uploads
.
count
).
to
eq
(
0
)
# Only 4 have been either confirmed or added to uploads
expect
(
un
hashed_upload_file
s
.
where
(
tracked:
true
).
count
).
to
eq
(
4
)
expect
(
un
tracked_files_for_upload
s
.
where
(
tracked:
true
).
count
).
to
eq
(
4
)
end
it
'uses the start and end batch ids [only 2nd half]'
do
start_id
=
un
hashed_upload_file
s
.
all
.
to_a
[
4
].
id
end_id
=
un
hashed_upload_file
s
.
all
.
to_a
[
7
].
id
start_id
=
un
tracked_files_for_upload
s
.
all
.
to_a
[
4
].
id
end_id
=
un
tracked_files_for_upload
s
.
all
.
to_a
[
7
].
id
expect
do
described_class
.
new
.
perform
(
start_id
,
end_id
)
...
...
@@ -100,7 +100,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
expect
(
project2
.
uploads
.
count
).
to
eq
(
2
)
# Only 4 have been either confirmed or added to uploads
expect
(
un
hashed_upload_file
s
.
where
(
tracked:
true
).
count
).
to
eq
(
4
)
expect
(
un
tracked_files_for_upload
s
.
where
(
tracked:
true
).
count
).
to
eq
(
4
)
end
end
...
...
@@ -113,7 +113,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads, :migration, :sid
end
end
describe
Gitlab
::
BackgroundMigration
::
PopulateUntrackedUploads
::
Un
hashedUploa
dFile
do
describe
Gitlab
::
BackgroundMigration
::
PopulateUntrackedUploads
::
Un
tracke
dFile
do
include
TrackUntrackedUploadsHelpers
let
(
:upload_class
)
{
Gitlab
::
BackgroundMigration
::
PopulateUntrackedUploads
::
Upload
}
...
...
@@ -122,7 +122,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
let
(
:user1
)
{
create
(
:user
)
}
context
'when the file is already in the uploads table'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/
#{
user1
.
id
}
/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/
#{
user1
.
id
}
/avatar.jpg"
)
}
before
do
upload_class
.
create!
(
path:
"uploads/-/system/user/avatar/
#{
user1
.
id
}
/avatar.jpg"
,
uploader:
'AvatarUploader'
,
model_type:
'User'
,
model_id:
user1
.
id
,
size:
1234
)
...
...
@@ -130,7 +130,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
it
'does not add an upload'
do
expect
do
un
hashed_uploa
d_file
.
ensure_tracked!
un
tracke
d_file
.
ensure_tracked!
end
.
not_to
change
{
upload_class
.
count
}.
from
(
1
)
end
end
...
...
@@ -142,7 +142,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for an appearance logo file path'
do
let
(
:model
)
{
create
(
:appearance
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
model
.
logo
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
model
.
logo
.
file
.
file
)
}
before
do
model
.
update!
(
logo:
uploaded_file
)
...
...
@@ -151,7 +151,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
it
'creates an Upload record'
do
expect
do
un
hashed_uploa
d_file
.
add_to_uploads
un
tracke
d_file
.
add_to_uploads
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
({
...
...
@@ -163,7 +163,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for an appearance header_logo file path'
do
let
(
:model
)
{
create
(
:appearance
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
model
.
header_logo
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
model
.
header_logo
.
file
.
file
)
}
before
do
model
.
update!
(
header_logo:
uploaded_file
)
...
...
@@ -172,7 +172,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
it
'creates an Upload record'
do
expect
do
un
hashed_uploa
d_file
.
add_to_uploads
un
tracke
d_file
.
add_to_uploads
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
({
...
...
@@ -184,7 +184,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for a pre-Markdown Note attachment file path'
do
let
(
:model
)
{
create
(
:note
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
model
.
attachment
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
model
.
attachment
.
file
.
file
)
}
before
do
model
.
update!
(
attachment:
uploaded_file
)
...
...
@@ -193,7 +193,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
it
'creates an Upload record'
do
expect
do
un
hashed_uploa
d_file
.
add_to_uploads
un
tracke
d_file
.
add_to_uploads
end
.
to
change
{
upload_class
.
count
}.
from
(
0
).
to
(
1
)
expect
(
upload_class
.
first
.
attributes
).
to
include
({
...
...
@@ -207,7 +207,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for a user avatar file path'
do
let
(
:model
)
{
create
(
:user
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
model
.
avatar
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
model
.
avatar
.
file
.
file
)
}
before
do
model
.
update!
(
avatar:
uploaded_file
)
...
...
@@ -216,7 +216,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
it
'creates an Upload record'
do
expect
do
un
hashed_uploa
d_file
.
add_to_uploads
un
tracke
d_file
.
add_to_uploads
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
({
...
...
@@ -228,7 +228,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for a group avatar file path'
do
let
(
:model
)
{
create
(
:group
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
model
.
avatar
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
model
.
avatar
.
file
.
file
)
}
before
do
model
.
update!
(
avatar:
uploaded_file
)
...
...
@@ -237,7 +237,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
it
'creates an Upload record'
do
expect
do
un
hashed_uploa
d_file
.
add_to_uploads
un
tracke
d_file
.
add_to_uploads
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
({
...
...
@@ -251,7 +251,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for a project avatar file path'
do
let
(
:model
)
{
create
(
:project
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
model
.
avatar
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
model
.
avatar
.
file
.
file
)
}
before
do
model
.
update!
(
avatar:
uploaded_file
)
...
...
@@ -260,7 +260,7 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
it
'creates an Upload record'
do
expect
do
un
hashed_uploa
d_file
.
add_to_uploads
un
tracke
d_file
.
add_to_uploads
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
({
...
...
@@ -272,20 +272,20 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for a project Markdown attachment (notes, issues, MR descriptions) file path'
do
let
(
:model
)
{
create
(
:project
)
}
let
(
:un
hashed_upload_file
)
{
described_class
.
new
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
model
.
full_path
}
/
#{
model
.
uploads
.
first
.
path
}
"
)
}
let
(
:un
tracked_file
)
{
described_class
.
new
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
model
.
full_path
}
/
#{
model
.
uploads
.
first
.
path
}
"
)
}
before
do
UploadService
.
new
(
model
,
uploaded_file
,
FileUploader
).
execute
# Markdown upload
un
hashed_uploa
d_file
.
save!
un
tracke
d_file
.
save!
model
.
reload
.
uploads
.
delete_all
end
it
'creates an Upload record'
do
expect
do
un
hashed_uploa
d_file
.
add_to_uploads
un
tracke
d_file
.
add_to_uploads
end
.
to
change
{
model
.
reload
.
uploads
.
count
}.
from
(
0
).
to
(
1
)
hex_secret
=
un
hashed_uploa
d_file
.
path
.
match
(
/\/(\h+)\/rails_sample.jpg/
)[
1
]
hex_secret
=
un
tracke
d_file
.
path
.
match
(
/\/(\h+)\/rails_sample.jpg/
)[
1
]
expect
(
model
.
uploads
.
first
.
attributes
).
to
include
({
"path"
=>
"
#{
hex_secret
}
/rails_sample.jpg"
,
"uploader"
=>
"FileUploader"
...
...
@@ -295,250 +295,250 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
end
describe
'#mark_as_tracked'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
it
'saves the record with tracked set to true'
do
expect
do
un
hashed_uploa
d_file
.
mark_as_tracked
end
.
to
change
{
un
hashed_uploa
d_file
.
tracked
}.
from
(
false
).
to
(
true
)
un
tracke
d_file
.
mark_as_tracked
end
.
to
change
{
un
tracke
d_file
.
tracked
}.
from
(
false
).
to
(
true
)
expect
(
un
hashed_uploa
d_file
.
persisted?
).
to
be_truthy
expect
(
un
tracke
d_file
.
persisted?
).
to
be_truthy
end
end
describe
'#upload_path'
do
context
'for an appearance logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
it
'returns the file path relative to the CarrierWave root'
do
expect
(
un
hashed_uploa
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/appearance/logo/1/some_logo.jpg'
)
expect
(
un
tracke
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/appearance/logo/1/some_logo.jpg'
)
end
end
context
'for an appearance header_logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
it
'returns the file path relative to the CarrierWave root'
do
expect
(
un
hashed_uploa
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/appearance/header_logo/1/some_logo.jpg'
)
expect
(
un
tracke
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/appearance/header_logo/1/some_logo.jpg'
)
end
end
context
'for a pre-Markdown Note attachment file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
it
'returns the file path relative to the CarrierWave root'
do
expect
(
un
hashed_uploa
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/note/attachment/1234/some_attachment.pdf'
)
expect
(
un
tracke
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/note/attachment/1234/some_attachment.pdf'
)
end
end
context
'for a user avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
it
'returns the file path relative to the CarrierWave root'
do
expect
(
un
hashed_uploa
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/user/avatar/1234/avatar.jpg'
)
expect
(
un
tracke
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/user/avatar/1234/avatar.jpg'
)
end
end
context
'for a group avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
it
'returns the file path relative to the CarrierWave root'
do
expect
(
un
hashed_uploa
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/group/avatar/1234/avatar.jpg'
)
expect
(
un
tracke
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/group/avatar/1234/avatar.jpg'
)
end
end
context
'for a project avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
it
'returns the file path relative to the CarrierWave root'
do
expect
(
un
hashed_uploa
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/project/avatar/1234/avatar.jpg'
)
expect
(
un
tracke
d_file
.
upload_path
).
to
eq
(
'uploads/-/system/project/avatar/1234/avatar.jpg'
)
end
end
context
'for a project Markdown attachment (notes, issues, MR descriptions) file path'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:random_hex
)
{
SecureRandom
.
hex
}
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
random_hex
}
/Some file.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
random_hex
}
/Some file.jpg"
)
}
it
'returns the file path relative to the project directory in uploads'
do
expect
(
un
hashed_uploa
d_file
.
upload_path
).
to
eq
(
"
#{
random_hex
}
/Some file.jpg"
)
expect
(
un
tracke
d_file
.
upload_path
).
to
eq
(
"
#{
random_hex
}
/Some file.jpg"
)
end
end
end
describe
'#uploader'
do
context
'for an appearance logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
it
'returns AttachmentUploader as a string'
do
expect
(
un
hashed_uploa
d_file
.
uploader
).
to
eq
(
'AttachmentUploader'
)
expect
(
un
tracke
d_file
.
uploader
).
to
eq
(
'AttachmentUploader'
)
end
end
context
'for an appearance header_logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
it
'returns AttachmentUploader as a string'
do
expect
(
un
hashed_uploa
d_file
.
uploader
).
to
eq
(
'AttachmentUploader'
)
expect
(
un
tracke
d_file
.
uploader
).
to
eq
(
'AttachmentUploader'
)
end
end
context
'for a pre-Markdown Note attachment file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
it
'returns AttachmentUploader as a string'
do
expect
(
un
hashed_uploa
d_file
.
uploader
).
to
eq
(
'AttachmentUploader'
)
expect
(
un
tracke
d_file
.
uploader
).
to
eq
(
'AttachmentUploader'
)
end
end
context
'for a user avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
it
'returns AvatarUploader as a string'
do
expect
(
un
hashed_uploa
d_file
.
uploader
).
to
eq
(
'AvatarUploader'
)
expect
(
un
tracke
d_file
.
uploader
).
to
eq
(
'AvatarUploader'
)
end
end
context
'for a group avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
it
'returns AvatarUploader as a string'
do
expect
(
un
hashed_uploa
d_file
.
uploader
).
to
eq
(
'AvatarUploader'
)
expect
(
un
tracke
d_file
.
uploader
).
to
eq
(
'AvatarUploader'
)
end
end
context
'for a project avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
it
'returns AvatarUploader as a string'
do
expect
(
un
hashed_uploa
d_file
.
uploader
).
to
eq
(
'AvatarUploader'
)
expect
(
un
tracke
d_file
.
uploader
).
to
eq
(
'AvatarUploader'
)
end
end
context
'for a project Markdown attachment (notes, issues, MR descriptions) file path'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
SecureRandom
.
hex
}
/Some file.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
SecureRandom
.
hex
}
/Some file.jpg"
)
}
it
'returns FileUploader as a string'
do
expect
(
un
hashed_uploa
d_file
.
uploader
).
to
eq
(
'FileUploader'
)
expect
(
un
tracke
d_file
.
uploader
).
to
eq
(
'FileUploader'
)
end
end
end
describe
'#model_type'
do
context
'for an appearance logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
it
'returns Appearance as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_type
).
to
eq
(
'Appearance'
)
expect
(
un
tracke
d_file
.
model_type
).
to
eq
(
'Appearance'
)
end
end
context
'for an appearance header_logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
it
'returns Appearance as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_type
).
to
eq
(
'Appearance'
)
expect
(
un
tracke
d_file
.
model_type
).
to
eq
(
'Appearance'
)
end
end
context
'for a pre-Markdown Note attachment file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
it
'returns Note as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_type
).
to
eq
(
'Note'
)
expect
(
un
tracke
d_file
.
model_type
).
to
eq
(
'Note'
)
end
end
context
'for a user avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
it
'returns User as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_type
).
to
eq
(
'User'
)
expect
(
un
tracke
d_file
.
model_type
).
to
eq
(
'User'
)
end
end
context
'for a group avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
it
'returns Namespace as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_type
).
to
eq
(
'Namespace'
)
expect
(
un
tracke
d_file
.
model_type
).
to
eq
(
'Namespace'
)
end
end
context
'for a project avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
it
'returns Project as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_type
).
to
eq
(
'Project'
)
expect
(
un
tracke
d_file
.
model_type
).
to
eq
(
'Project'
)
end
end
context
'for a project Markdown attachment (notes, issues, MR descriptions) file path'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
SecureRandom
.
hex
}
/Some file.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
SecureRandom
.
hex
}
/Some file.jpg"
)
}
it
'returns Project as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_type
).
to
eq
(
'Project'
)
expect
(
un
tracke
d_file
.
model_type
).
to
eq
(
'Project'
)
end
end
end
describe
'#model_id'
do
context
'for an appearance logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/logo/1/some_logo.jpg"
)
}
it
'returns the ID as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_id
).
to
eq
(
'1'
)
expect
(
un
tracke
d_file
.
model_id
).
to
eq
(
'1'
)
end
end
context
'for an appearance header_logo file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/appearance/header_logo/1/some_logo.jpg"
)
}
it
'returns the ID as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_id
).
to
eq
(
'1'
)
expect
(
un
tracke
d_file
.
model_id
).
to
eq
(
'1'
)
end
end
context
'for a pre-Markdown Note attachment file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/note/attachment/1234/some_attachment.pdf"
)
}
it
'returns the ID as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_id
).
to
eq
(
'1234'
)
expect
(
un
tracke
d_file
.
model_id
).
to
eq
(
'1234'
)
end
end
context
'for a user avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/user/avatar/1234/avatar.jpg"
)
}
it
'returns the ID as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_id
).
to
eq
(
'1234'
)
expect
(
un
tracke
d_file
.
model_id
).
to
eq
(
'1234'
)
end
end
context
'for a group avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/group/avatar/1234/avatar.jpg"
)
}
it
'returns the ID as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_id
).
to
eq
(
'1234'
)
expect
(
un
tracke
d_file
.
model_id
).
to
eq
(
'1234'
)
end
end
context
'for a project avatar file path'
do
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/-/system/project/avatar/1234/avatar.jpg"
)
}
it
'returns the ID as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_id
).
to
eq
(
'1234'
)
expect
(
un
tracke
d_file
.
model_id
).
to
eq
(
'1234'
)
end
end
context
'for a project Markdown attachment (notes, issues, MR descriptions) file path'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
SecureRandom
.
hex
}
/Some file.jpg"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
SecureRandom
.
hex
}
/Some file.jpg"
)
}
it
'returns the ID as a string'
do
expect
(
un
hashed_uploa
d_file
.
model_id
).
to
eq
(
project
.
id
.
to_s
)
expect
(
un
tracke
d_file
.
model_id
).
to
eq
(
project
.
id
.
to_s
)
end
end
end
...
...
@@ -549,52 +549,52 @@ describe Gitlab::BackgroundMigration::PopulateUntrackedUploads::UnhashedUploadFi
context
'for an appearance logo file path'
do
let
(
:appearance
)
{
create
(
:appearance
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
appearance
.
logo
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
appearance
.
logo
.
file
.
file
)
}
before
do
appearance
.
update!
(
logo:
uploaded_file
)
end
it
'returns the file size'
do
expect
(
un
hashed_uploa
d_file
.
file_size
).
to
eq
(
35255
)
expect
(
un
tracke
d_file
.
file_size
).
to
eq
(
35255
)
end
it
'returns the same thing that CarrierWave would return'
do
expect
(
un
hashed_uploa
d_file
.
file_size
).
to
eq
(
appearance
.
logo
.
size
)
expect
(
un
tracke
d_file
.
file_size
).
to
eq
(
appearance
.
logo
.
size
)
end
end
context
'for a project avatar file path'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:un
hashed_uploa
d_file
)
{
described_class
.
create!
(
path:
project
.
avatar
.
file
.
file
)
}
let
(
:un
tracke
d_file
)
{
described_class
.
create!
(
path:
project
.
avatar
.
file
.
file
)
}
before
do
project
.
update!
(
avatar:
uploaded_file
)
end
it
'returns the file size'
do
expect
(
un
hashed_uploa
d_file
.
file_size
).
to
eq
(
35255
)
expect
(
un
tracke
d_file
.
file_size
).
to
eq
(
35255
)
end
it
'returns the same thing that CarrierWave would return'
do
expect
(
un
hashed_uploa
d_file
.
file_size
).
to
eq
(
project
.
avatar
.
size
)
expect
(
un
tracke
d_file
.
file_size
).
to
eq
(
project
.
avatar
.
size
)
end
end
context
'for a project Markdown attachment (notes, issues, MR descriptions) file path'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:un
hashed_upload_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUnhash
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
project
.
uploads
.
first
.
path
}
"
)
}
let
(
:un
tracked_file
)
{
described_class
.
create!
(
path:
"
#{
Gitlab
::
BackgroundMigration
::
PrepareUntrack
edUploads
::
UPLOAD_DIR
}
/
#{
project
.
full_path
}
/
#{
project
.
uploads
.
first
.
path
}
"
)
}
before
do
UploadService
.
new
(
project
,
uploaded_file
,
FileUploader
).
execute
end
it
'returns the file size'
do
expect
(
un
hashed_uploa
d_file
.
file_size
).
to
eq
(
35255
)
expect
(
un
tracke
d_file
.
file_size
).
to
eq
(
35255
)
end
it
'returns the same thing that CarrierWave would return'
do
expect
(
un
hashed_uploa
d_file
.
file_size
).
to
eq
(
project
.
uploads
.
first
.
size
)
expect
(
un
tracke
d_file
.
file_size
).
to
eq
(
project
.
uploads
.
first
.
size
)
end
end
end
...
...
spec/lib/gitlab/background_migration/prepare_un
hash
ed_uploads_spec.rb
→
spec/lib/gitlab/background_migration/prepare_un
track
ed_uploads_spec.rb
View file @
a210cb6b
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
PrepareUn
hash
edUploads
,
:migration
,
:sidekiq
,
schema:
20171103140253
do
let!
(
:un
hashed_upload_files
)
{
table
(
:unhashed_upload_file
s
)
}
describe
Gitlab
::
BackgroundMigration
::
PrepareUn
track
edUploads
,
:migration
,
:sidekiq
,
schema:
20171103140253
do
let!
(
:un
tracked_files_for_uploads
)
{
table
(
:untracked_files_for_upload
s
)
}
let
(
:user1
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
...
...
@@ -39,20 +39,20 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, :sidek
UploadService
.
new
(
project2
,
uploaded_file
,
FileUploader
).
execute
end
it
'adds unhashed files to the un
hashed_upload_file
s table'
do
it
'adds unhashed files to the un
tracked_files_for_upload
s table'
do
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
to
change
{
un
hashed_upload_file
s
.
count
}.
from
(
0
).
to
(
5
)
end
.
to
change
{
un
tracked_files_for_upload
s
.
count
}.
from
(
0
).
to
(
5
)
end
end
it
'does not add hashed files to the un
hashed_upload_file
s table'
do
it
'does not add hashed files to the un
tracked_files_for_upload
s table'
do
Sidekiq
::
Testing
.
fake!
do
described_class
.
new
.
perform
hashed_file_path
=
project2
.
uploads
.
where
(
uploader:
'FileUploader'
).
first
.
path
expect
(
un
hashed_upload_file
s
.
where
(
"path like '%
#{
hashed_file_path
}
%'"
).
exists?
).
to
be_falsey
expect
(
un
tracked_files_for_upload
s
.
where
(
"path like '%
#{
hashed_file_path
}
%'"
).
exists?
).
to
be_falsey
end
end
...
...
@@ -66,16 +66,16 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, :sidek
end
# E.g. from a previous failed run of this background migration
context
'when there is existing data in un
hashed_upload_file
s'
do
context
'when there is existing data in un
tracked_files_for_upload
s'
do
before
do
un
hashed_upload_file
s
.
create
(
path:
'/foo/bar.jpg'
)
un
tracked_files_for_upload
s
.
create
(
path:
'/foo/bar.jpg'
)
end
it
'clears existing data before adding new data'
do
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
to
change
{
un
hashed_upload_file
s
.
count
}.
from
(
1
).
to
(
5
)
end
.
to
change
{
un
tracked_files_for_upload
s
.
count
}.
from
(
1
).
to
(
5
)
end
end
end
...
...
@@ -91,7 +91,7 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, :sidek
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
to
change
{
un
hashed_upload_file
s
.
count
}.
from
(
0
).
to
(
5
)
end
.
to
change
{
un
tracked_files_for_upload
s
.
count
}.
from
(
0
).
to
(
5
)
end
end
end
...
...
@@ -100,11 +100,11 @@ describe Gitlab::BackgroundMigration::PrepareUnhashedUploads, :migration, :sidek
# Very new or lightly-used installations that are running this migration
# may not have an upload directory because they have no uploads.
context
'when no files were ever uploaded'
do
it
'does not add to the un
hashed_upload_file
s table (and does not raise error)'
do
it
'does not add to the un
tracked_files_for_upload
s table (and does not raise error)'
do
Sidekiq
::
Testing
.
fake!
do
expect
do
described_class
.
new
.
perform
end
.
not_to
change
{
un
hashed_upload_file
s
.
count
}.
from
(
0
)
end
.
not_to
change
{
un
tracked_files_for_upload
s
.
count
}.
from
(
0
)
end
end
end
...
...
spec/migrations/track_untracked_uploads_spec.rb
View file @
a210cb6b
...
...
@@ -4,8 +4,8 @@ require Rails.root.join('db', 'post_migrate', '20171103140253_track_untracked_up
describe
TrackUntrackedUploads
,
:migration
,
:sidekiq
do
include
TrackUntrackedUploadsHelpers
class
Un
hashedUploa
dFile
<
ActiveRecord
::
Base
self
.
table_name
=
'un
hashed_upload_file
s'
class
Un
tracke
dFile
<
ActiveRecord
::
Base
self
.
table_name
=
'un
tracked_files_for_upload
s'
end
matcher
:be_scheduled_migration
do
...
...
@@ -29,10 +29,10 @@ describe TrackUntrackedUploads, :migration, :sidekiq do
end
end
it
'ensures the un
hashed_upload_file
s table exists'
do
it
'ensures the un
tracked_files_for_upload
s table exists'
do
expect
do
migrate!
end
.
to
change
{
table_exists?
(
:un
hashed_upload_file
s
)
}.
from
(
false
).
to
(
true
)
end
.
to
change
{
table_exists?
(
:un
tracked_files_for_upload
s
)
}.
from
(
false
).
to
(
true
)
end
it
'has a path field long enough for really long paths'
do
...
...
@@ -48,7 +48,7 @@ describe TrackUntrackedUploads, :migration, :sidekiq do
component
# filename
].
flatten
.
join
(
'/'
)
record
=
Un
hashedUploa
dFile
.
create!
(
path:
long_path
)
record
=
Un
tracke
dFile
.
create!
(
path:
long_path
)
expect
(
record
.
reload
.
path
.
size
).
to
eq
(
5711
)
end
...
...
@@ -132,12 +132,12 @@ describe TrackUntrackedUploads, :migration, :sidekiq do
end
end
it
'all Un
hashedUploa
dFile records are marked as tracked'
do
it
'all Un
tracke
dFile records are marked as tracked'
do
Sidekiq
::
Testing
.
inline!
do
migrate!
expect
(
Un
hashedUploa
dFile
.
count
).
to
eq
(
8
)
expect
(
Un
hashedUploadFile
.
count
).
to
eq
(
UnhashedUploa
dFile
.
where
(
tracked:
true
).
count
)
expect
(
Un
tracke
dFile
.
count
).
to
eq
(
8
)
expect
(
Un
trackedFile
.
count
).
to
eq
(
Untracke
dFile
.
where
(
tracked:
true
).
count
)
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