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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
175f7f68
Commit
175f7f68
authored
Mar 31, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move files for moved namespaces.
parent
1d829ca1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
8 deletions
+39
-8
app/models/namespace.rb
app/models/namespace.rb
+0
-4
db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
...ate/20150324133047_remove_periods_at_ends_of_usernames.rb
+39
-2
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+0
-2
No files found.
app/models/namespace.rb
View file @
175f7f68
...
...
@@ -58,10 +58,6 @@ class Namespace < ActiveRecord::Base
where
(
"name LIKE :query OR path LIKE :query"
,
query:
"%
#{
query
}
%"
)
end
def
global_id
'GLN'
end
def
clean_path
(
path
)
path
.
gsub!
(
/@.*\z/
,
""
)
path
.
gsub!
(
/\.git\z/
,
""
)
...
...
db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
View file @
175f7f68
class
RemovePeriodsAtEndsOfUsernames
<
ActiveRecord
::
Migration
include
Gitlab
::
ShellAdapter
class
Namespace
<
ActiveRecord
::
Base
class
<<
self
def
by_path
(
path
)
...
...
@@ -6,6 +8,7 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration
end
def
clean_path
(
path
)
path
=
path
.
dup
path
.
gsub!
(
/@.*\z/
,
""
)
path
.
gsub!
(
/\.git\z/
,
""
)
path
.
gsub!
(
/\A-/
,
""
)
...
...
@@ -25,15 +28,49 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration
end
def
up
changed_paths
=
{}
select_all
(
"SELECT id, username FROM users WHERE username LIKE '%.'"
).
each
do
|
user
|
username
=
quote_string
(
Namespace
.
clean_path
(
user
[
"username"
]))
username_was
=
user
[
"username"
]
username
=
Namespace
.
clean_path
(
username_was
)
changed_paths
[
username_was
]
=
username
username
=
quote_string
(
username
)
execute
"UPDATE users SET username = '
#{
username
}
' WHERE id =
#{
user
[
"id"
]
}
"
execute
"UPDATE namespaces SET path = '
#{
username
}
', name = '
#{
username
}
' WHERE type = NULL AND owner_id =
#{
user
[
"id"
]
}
"
end
select_all
(
"SELECT id, path FROM namespaces WHERE type = 'Group' AND path LIKE '%.'"
).
each
do
|
group
|
path
=
quote_string
(
Namespace
.
clean_path
(
group
[
"path"
]))
path_was
=
group
[
"path"
]
path
=
Namespace
.
clean_path
(
path_was
)
changed_paths
[
path_was
]
=
path
path
=
quote_string
(
path
)
execute
"UPDATE namespaces SET path = '
#{
path
}
' WHERE id =
#{
group
[
"id"
]
}
"
end
changed_paths
.
each
do
|
path_was
,
path
|
if
gitlab_shell
.
mv_namespace
(
path_was
,
path
)
# If repositories moved successfully we need to remove old satellites
# and send update instructions to users.
# However we cannot allow rollback since we moved namespace dir
# So we basically we mute exceptions in next actions
begin
gitlab_shell
.
rm_satellites
(
path_was
)
# We cannot send update instructions since models and mailers
# can't safely be used from migrations as they may be written for
# later versions of the database.
# send_update_instructions
rescue
# Returning false does not rollback after_* transaction but gives
# us information about failing some of tasks
false
end
else
# if we cannot move namespace directory we should rollback
# db changes in order to prevent out of sync between db and fs
raise
Exception
.
new
(
'namespace directory cannot be moved'
)
end
end
end
end
spec/models/namespace_spec.rb
View file @
175f7f68
...
...
@@ -33,8 +33,6 @@ describe Namespace do
it
{
is_expected
.
to
respond_to
(
:to_param
)
}
end
it
{
expect
(
Namespace
.
global_id
).
to
eq
(
'GLN'
)
}
describe
:to_param
do
it
{
expect
(
namespace
.
to_param
).
to
eq
(
namespace
.
path
)
}
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