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
c156030e
Commit
c156030e
authored
Jul 17, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a background migration to rename `uploads` in the uploads table
parent
79f591df
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
1 deletion
+87
-1
db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb
...717150329_enqueue_migrate_system_uploads_to_new_folder.rb
+20
-0
db/schema.rb
db/schema.rb
+1
-1
lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
...kground_migration/migrate_system_uploads_to_new_folder.rb
+47
-0
spec/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder_spec.rb
...nd_migration/migrate_system_uploads_to_new_folder_spec.rb
+19
-0
No files found.
db/post_migrate/20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb
0 → 100644
View file @
c156030e
class
EnqueueMigrateSystemUploadsToNewFolder
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
OLD_FOLDER
=
'uploads/system/'
NEW_FOLDER
=
'uploads/-/system/'
disable_ddl_transaction!
def
up
BackgroundMigrationWorker
.
perform_async
(
'MigrateSystemUploadsToNewFolder'
,
[
OLD_FOLDER
,
NEW_FOLDER
])
end
def
down
BackgroundMigrationWorker
.
perform_async
(
'MigrateSystemUploadsToNewFolder'
,
[
NEW_FOLDER
,
OLD_FOLDER
])
end
end
db/schema.rb
View file @
c156030e
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201707171
11152
)
do
ActiveRecord
::
Schema
.
define
(
version:
201707171
50329
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
0 → 100644
View file @
c156030e
module
Gitlab
module
BackgroundMigration
class
MigrateSystemUploadsToNewFolder
include
Gitlab
::
Database
::
MigrationHelpers
attr_reader
:old_folder
,
:new_folder
def
perform
(
old_folder
,
new_folder
)
@old_folder
=
old_folder
@new_folder
=
new_folder
replace_sql
=
replace_sql
(
uploads
[
:path
],
old_folder
,
new_folder
)
while
remaining_rows
>
0
sql
=
"UPDATE uploads "
\
"SET path =
#{
replace_sql
}
"
\
"WHERE uploads.id IN "
\
" (SELECT uploads.id FROM uploads "
\
" WHERE
#{
affected_uploads
.
to_sql
}
LIMIT 1000)"
connection
.
execute
(
sql
)
end
end
def
uploads
Arel
::
Table
.
new
(
'uploads'
)
end
def
remaining_rows
remaining_result
=
connection
.
exec_query
(
"SELECT count(id) FROM uploads WHERE
#{
affected_uploads
.
to_sql
}
"
)
remaining
=
remaining_result
.
first
[
'count'
].
to_i
logger
.
info
"
#{
remaining
}
uploads remaining"
remaining
end
def
affected_uploads
uploads
[
:path
].
matches
(
"
#{
old_folder
}
%"
)
end
def
connection
ActiveRecord
::
Base
.
connection
end
def
logger
Sidekiq
.
logger
||
Rails
.
logger
||
Logger
.
new
(
STDOUT
)
end
end
end
end
spec/lib/gitlab/background_migration/migrate_system_uploads_to_new_folder_spec.rb
0 → 100644
View file @
c156030e
require
'spec_helper'
describe
Gitlab
::
BackgroundMigration
::
MigrateSystemUploadsToNewFolder
do
let
(
:migration
)
{
described_class
.
new
}
before
do
allow
(
migration
).
to
receive
(
:logger
).
and_return
(
Logger
.
new
(
nil
))
end
describe
'#perform'
do
it
'renames the path of system-uploads'
,
truncate:
true
do
upload
=
create
(
:upload
,
model:
create
(
:empty_project
),
path:
'uploads/system/project/avatar.jpg'
)
migration
.
perform
(
'uploads/system/'
,
'uploads/-/system/'
)
expect
(
upload
.
reload
.
path
).
to
eq
(
'uploads/-/system/project/avatar.jpg'
)
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