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
6f26f6f7
Commit
6f26f6f7
authored
Jul 17, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow groups with the name system
parent
6a10626f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
31 deletions
+9
-31
lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
...kground_migration/migrate_system_uploads_to_new_folder.rb
+8
-29
lib/gitlab/path_regex.rb
lib/gitlab/path_regex.rb
+0
-1
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+1
-1
No files found.
lib/gitlab/background_migration/migrate_system_uploads_to_new_folder.rb
View file @
6f26f6f7
...
...
@@ -4,44 +4,23 @@ module Gitlab
include
Gitlab
::
Database
::
MigrationHelpers
attr_reader
:old_folder
,
:new_folder
def
perform
(
old_folder
,
new_folder
)
@old_folder
=
old_folder
@new_folder
=
new_folder
class
Upload
<
ActiveRecord
::
Base
self
.
table_name
=
'uploads'
include
EachBatch
end
def
perform
(
old_folder
,
new_folder
)
replace_sql
=
replace_sql
(
uploads
[
:path
],
old_folder
,
new_folder
)
affected_uploads
=
Upload
.
where
(
uploads
[
:path
].
matches
(
"
#{
old_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
)
affected_uploads
.
each_batch
do
|
batch
|
batch
.
update_all
(
"path =
#{
replace_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
lib/gitlab/path_regex.rb
View file @
6f26f6f7
...
...
@@ -49,7 +49,6 @@ module Gitlab
sent_notifications
services
snippets
system
teams
u
unicorn_test
...
...
spec/models/namespace_spec.rb
View file @
6f26f6f7
...
...
@@ -44,7 +44,7 @@ describe Namespace, models: true do
end
context
"is case insensitive"
do
let
(
:group
)
{
build
(
:group
,
path:
"
System
"
)
}
let
(
:group
)
{
build
(
:group
,
path:
"
Groups
"
)
}
it
{
expect
(
group
).
not_to
be_valid
}
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