summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-02-01 15:47:11 +0100
committerJames Lopez <james@jameslopez.es>2016-02-01 15:47:11 +0100
commit927ab48101d44976e174b13323d085aa5f846155 (patch)
treee8a1ccc7068b343c472db950ee5d81c69c8aa18e
parent7dffec2c43116fa339f967b1005f23442752ce0d (diff)
downloadgitlab-ce-927ab48101d44976e174b13323d085aa5f846155.tar.gz
WIP - refactored migration
-rw-r--r--CHANGELOG1
-rw-r--r--db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb49
2 files changed, 43 insertions, 7 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fe0504ec996..2e6e65e7ae2 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb b/db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb
index c7b986aca91..622b0f5db08 100644
--- a/db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb
+++ b/db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb
@@ -1,8 +1,12 @@
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