diff options
author | James Lopez <james@jameslopez.es> | 2016-02-02 17:28:14 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-02-02 17:28:14 +0100 |
commit | ecb174bfeadffbccc5c5cf35b6e94b65f5fbce79 (patch) | |
tree | 8ea654ab13ec3e544950625319ab8d960a0b8ca7 /db | |
parent | ae73e73beef078b83955bf55dcf3e07cbe5afcf5 (diff) | |
download | gitlab-ce-ecb174bfeadffbccc5c5cf35b6e94b65f5fbce79.tar.gz |
fixed move project method in migration
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20160129135155_remove_dot_atom_path_ending_of_projects.rb | 46 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 14 insertions, 34 deletions
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 0bc23f5627f..9ca695d713f 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 @@ -2,11 +2,12 @@ class RemoveDotAtomPathEndingOfProjects < ActiveRecord::Migration include Gitlab::ShellAdapter class ProjectPath - attr_reader :old_path, :id + attr_reader :old_path, :id, :namespace_path - def initialize(old_path, id) + def initialize(old_path, id, namespace_path) @old_path = old_path @id = id + @namespace_path = namespace_path end def clean_path @@ -43,48 +44,27 @@ class RemoveDotAtomPathEndingOfProjects < ActiveRecord::Migration end def projects_with_dot_atom - select_all("SELECT id, path FROM projects WHERE lower(path) LIKE '%.atom'") + select_all("SELECT p.id, p.path, n.path as namespace_path FROM projects p inner join namespaces n on n.id = p.namespace_id WHERE lower(p.path) LIKE '%.atom'") end def up projects_with_dot_atom.each do |project| - binding.pry - project_path = ProjectPath.new(project['path'], project['id']) - clean_path(project_path) if move_path(project_path) + project_path = ProjectPath.new(project['path'], project['id'], project['namespace_path']) + clean_path(project_path) if rename_project_repo(project_path) end end private def clean_path(project_path) - execute "UPDATE projects SET path = '#{project_path.clean_path}' WHERE id = #{project.id}" + execute "UPDATE projects SET path = '#{project_path.clean_path}' WHERE id = #{project_path.id}" end - #TODO: Fix this - 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 + def rename_project_repo(project_path) + old_path_with_namespace = File.join(project_path.namespace_path, project_path.old_path) + new_path_with_namespace = File.join(project_path.namespace_path, project_path.clean_path) + + gitlab_shell.mv_repository("#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki") + gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace) end end diff --git a/db/schema.rb b/db/schema.rb index 2ad2c23fba5..ad9e9e8a5de 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160128233227) do +ActiveRecord::Schema.define(version: 20160129135155) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |