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
79f591df
Commit
79f591df
authored
Jul 17, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the `uploads/system` folder to `uploads/-/system`
Without downtime, so we need the symlinks
parent
27a6aa4f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
198 additions
and
1 deletion
+198
-1
db/migrate/20170717074009_move_system_upload_folder.rb
db/migrate/20170717074009_move_system_upload_folder.rb
+60
-0
db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb
...170717111152_cleanup_move_system_upload_folder_symlink.rb
+40
-0
db/schema.rb
db/schema.rb
+1
-1
spec/migrations/cleanup_move_system_upload_folder_symlink_spec.rb
...rations/cleanup_move_system_upload_folder_symlink_spec.rb
+35
-0
spec/migrations/move_system_upload_folder_spec.rb
spec/migrations/move_system_upload_folder_spec.rb
+62
-0
No files found.
db/migrate/20170717074009_move_system_upload_folder.rb
0 → 100644
View file @
79f591df
class
MoveSystemUploadFolder
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
DOWNTIME
=
false
def
up
unless
file_storage?
say
'Using object storage, no need to move.'
return
end
unless
File
.
directory?
(
old_directory
)
say
"
#{
old_directory
}
doesn't exist, no need to move it."
return
end
FileUtils
.
mkdir_p
(
File
.
join
(
base_directory
,
'-'
))
say
"Moving
#{
old_directory
}
->
#{
new_directory
}
"
FileUtils
.
mv
(
old_directory
,
new_directory
)
FileUtils
.
ln_s
(
new_directory
,
old_directory
)
end
def
down
unless
file_storage?
say
'Using object storage, no need to move.'
return
end
unless
File
.
directory?
(
new_directory
)
say
"
#{
new_directory
}
doesn't exist, no need to move it."
return
end
if
File
.
symlink?
(
old_directory
)
say
"Removing
#{
old_directory
}
->
#{
new_directory
}
symlink"
FileUtils
.
rm
(
old_directory
)
end
say
"Moving
#{
new_directory
}
->
#{
old_directory
}
"
FileUtils
.
mv
(
new_directory
,
old_directory
)
end
def
new_directory
File
.
join
(
base_directory
,
'-'
,
'system'
)
end
def
old_directory
File
.
join
(
base_directory
,
'system'
)
end
def
base_directory
File
.
join
(
Rails
.
root
,
'public'
,
'uploads'
)
end
def
file_storage?
CarrierWave
::
Uploader
::
Base
.
storage
==
CarrierWave
::
Storage
::
File
end
end
db/post_migrate/20170717111152_cleanup_move_system_upload_folder_symlink.rb
0 → 100644
View file @
79f591df
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
CleanupMoveSystemUploadFolderSymlink
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
if
File
.
symlink?
(
old_directory
)
say
"Removing
#{
old_directory
}
->
#{
new_directory
}
symlink"
FileUtils
.
rm
(
old_directory
)
else
say
"Symlink
#{
old_directory
}
non existant, nothing to do."
end
end
def
down
if
File
.
directory?
(
new_directory
)
say
"Symlinking
#{
old_directory
}
->
#{
new_directory
}
"
FileUtils
.
ln_s
(
new_directory
,
old_directory
)
else
say
"
#{
new_directory
}
doesn't exist, skipping."
end
end
def
new_directory
File
.
join
(
base_directory
,
'-'
,
'system'
)
end
def
old_directory
File
.
join
(
base_directory
,
'system'
)
end
def
base_directory
File
.
join
(
Rails
.
root
,
'public'
,
'uploads'
)
end
end
db/schema.rb
View file @
79f591df
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017071
3104829
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017071
7111152
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
spec/migrations/cleanup_move_system_upload_folder_symlink_spec.rb
0 → 100644
View file @
79f591df
require
'spec_helper'
require
Rails
.
root
.
join
(
"db"
,
"post_migrate"
,
"20170717111152_cleanup_move_system_upload_folder_symlink.rb"
)
describe
CleanupMoveSystemUploadFolderSymlink
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:test_base
)
{
File
.
join
(
Rails
.
root
,
'tmp'
,
'tests'
,
'move-system-upload-folder'
)
}
let
(
:test_folder
)
{
File
.
join
(
test_base
,
'-'
,
'system'
)
}
before
do
allow
(
migration
).
to
receive
(
:base_directory
).
and_return
(
test_base
)
FileUtils
.
rm_rf
(
test_base
)
FileUtils
.
mkdir_p
(
test_folder
)
allow
(
migration
).
to
receive
(
:say
)
end
describe
'#up'
do
before
do
FileUtils
.
ln_s
(
test_folder
,
File
.
join
(
test_base
,
'system'
))
end
it
'removes the symlink'
do
migration
.
up
expect
(
File
.
exist?
(
File
.
join
(
test_base
,
'system'
))).
to
be_falsey
end
end
describe
'#down'
do
it
'creates the symlink'
do
migration
.
down
expect
(
File
.
symlink?
(
File
.
join
(
test_base
,
'system'
))).
to
be_truthy
end
end
end
spec/migrations/move_system_upload_folder_spec.rb
0 → 100644
View file @
79f591df
require
'spec_helper'
require
Rails
.
root
.
join
(
"db"
,
"migrate"
,
"20170717074009_move_system_upload_folder.rb"
)
describe
MoveSystemUploadFolder
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:test_base
)
{
File
.
join
(
Rails
.
root
,
'tmp'
,
'tests'
,
'move-system-upload-folder'
)
}
before
do
allow
(
migration
).
to
receive
(
:base_directory
).
and_return
(
test_base
)
FileUtils
.
rm_rf
(
test_base
)
FileUtils
.
mkdir_p
(
test_base
)
allow
(
migration
).
to
receive
(
:say
)
end
describe
'#up'
do
let
(
:test_folder
)
{
File
.
join
(
test_base
,
'system'
)
}
let
(
:test_file
)
{
File
.
join
(
test_folder
,
'file'
)
}
before
do
FileUtils
.
mkdir_p
(
test_folder
)
FileUtils
.
touch
(
test_file
)
end
it
'moves the related folder'
do
migration
.
up
expect
(
File
.
exist?
(
File
.
join
(
test_base
,
'-'
,
'system'
,
'file'
))).
to
be_truthy
end
it
'creates a symlink linking making the new folder available on the old path'
do
migration
.
up
expect
(
File
.
symlink?
(
File
.
join
(
test_base
,
'system'
))).
to
be_truthy
expect
(
File
.
exist?
(
File
.
join
(
test_base
,
'system'
,
'file'
))).
to
be_truthy
end
end
describe
'#down'
do
let
(
:test_folder
)
{
File
.
join
(
test_base
,
'-'
,
'system'
)
}
let
(
:test_file
)
{
File
.
join
(
test_folder
,
'file'
)
}
before
do
FileUtils
.
mkdir_p
(
test_folder
)
FileUtils
.
touch
(
test_file
)
end
it
'moves the system folder back to the old location'
do
migration
.
down
expect
(
File
.
exist?
(
File
.
join
(
test_base
,
'system'
,
'file'
))).
to
be_truthy
end
it
'removes the symlink if it existed'
do
FileUtils
.
ln_s
(
test_folder
,
File
.
join
(
test_base
,
'system'
))
migration
.
down
expect
(
File
.
directory?
(
File
.
join
(
test_base
,
'system'
))).
to
be_truthy
expect
(
File
.
symlink?
(
File
.
join
(
test_base
,
'system'
))).
to
be_falsey
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