Commit 927ab481 authored by James Lopez's avatar James Lopez

WIP - refactored migration

parent 7dffec2c
No related merge requests found
......@@ -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
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment