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
iv
gitlab-ce
Commits
927ab481
Commit
927ab481
authored
Feb 01, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP - refactored migration
parent
7dffec2c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
7 deletions
+43
-7
CHANGELOG
CHANGELOG
+1
-0
db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb
...20160129135155_remove_dot_atom_path_ending_of_projects.rb
+42
-7
No files found.
CHANGELOG
View file @
927ab481
...
...
@@ -17,6 +17,7 @@ v 8.5.0 (unreleased)
- Update the ExternalIssue regex pattern (Blake Hitchcock)
- Deprecate API "merge_request/:merge_request_id/comments". Use "merge_requests/:merge_request_id/notes" instead
- Deprecate API "merge_request/:merge_request_id/...". Use "merge_requests/:merge_request_id/..." instead
- Prevent parse error when name of project ends with .atom and prevent path issues
v 8.4.2
- Bump required gitlab-workhorse version to bring in a fix for missing
...
...
db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb
View file @
927ab481
class
RemoveDotAtomPathEndingOfProjects
<
ActiveRecord
::
Migration
include
Gitlab
::
ShellAdapter
class
ProjectPath
def
initilize
(
old_path
)
attr_reader
:old_path
,
:id
def
initialize
(
old_path
,
id
)
@old_path
=
old_path
@id
=
id
end
def
clean_path
...
...
@@ -10,7 +14,7 @@ class RemoveDotAtomPathEndingOfProjects < ActiveRecord::Migration
end
end
module
PathCleaner
class
PathCleaner
def
initialize
(
path
)
@path
=
path
end
...
...
@@ -30,7 +34,7 @@ class RemoveDotAtomPathEndingOfProjects < ActiveRecord::Migration
end
def
cleaned_path
@_cleaned_path
||=
path
.
gsub
(
/\.atom\z/
,
'-atom'
)
@_cleaned_path
||=
@
path
.
gsub
(
/\.atom\z/
,
'-atom'
)
end
def
path_exists?
(
path
)
...
...
@@ -38,17 +42,48 @@ class RemoveDotAtomPathEndingOfProjects < ActiveRecord::Migration
end
end
def
projects_with_dot_atom
select_all
(
"SELECT id, path FROM projects WHERE lower(path) LIKE '%.atom'"
)
end
def
up
projects_with_dot_atom
.
each
do
|
project
|
remove_dot
(
project
)
binding
.
pry
project_path
=
ProjectPath
.
new
(
project
[
'path'
],
project
[
'id'
])
clean_path
(
project_path
)
if
move_path
(
project_path
)
end
end
private
def
remove_dot
(
project
)
#TODO
def
clean_path
(
project_path
)
execute
"UPDATE projects SET path = '
#{
project_path
.
clean_path
}
' WHERE id =
#{
project
.
id
}
"
end
def
move_path
(
project_path
)
# Based on RemovePeriodsAtEndsOfUsernames
# Don't attempt to move if original path only contains periods.
return
if
project_path
.
clean_path
=~
/\A\.+\z/
if
gitlab_shell
.
mv_namespace
(
project_path
.
old_path
,
project_path
.
clean_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
(
project_path
.
old_path
)
# 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 avoid
# db changes in order to prevent out of sync between db and fs
false
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