Commit 152cba56 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Bob Van Landuyt

Revert namespace renames

parent 0faff42d
......@@ -28,6 +28,10 @@ module Gitlab
track_rename('namespace', old_full_path, new_full_path)
rename_namespace_dependencies(namespace, old_full_path, new_full_path)
end
def rename_namespace_dependencies(namespace, old_full_path, new_full_path)
move_repositories(namespace, old_full_path, new_full_path)
move_uploads(old_full_path, new_full_path)
move_pages(old_full_path, new_full_path)
......@@ -35,6 +39,23 @@ module Gitlab
remove_cached_html_for_projects(projects_for_namespace(namespace).map(&:id))
end
def revert_renames
reverts_for_type('namespace') do |path_before_rename, current_path|
matches_path = MigrationClasses::Route.arel_table[:path].matches(current_path)
namespace = MigrationClasses::Namespace.joins(:route)
.where(matches_path).first.becomes(MigrationClasses::Namespace)
if namespace
perform_rename(namespace, current_path, path_before_rename)
rename_namespace_dependencies(namespace, current_path, path_before_rename)
else
say "Couldn't rename namespace##{namespace.id} from #{current_path} "\
" back to #{path_before_rename}, namespace no longer exists"
end
end
end
def rename_user(old_username, new_username)
MigrationClasses::User.where(username: old_username)
.update_all(username: new_username)
......
......@@ -38,7 +38,8 @@ module Gitlab
move_project_folders(project, current_path, path_before_rename)
else
say "Couldn't rename project##{project.id} from #{current_path} back to #{path_before_rename}, project no longer exists"
say "Couldn't rename project##{project.id} from #{current_path} "\
"back to #{path_before_rename}, project no longer exists"
end
end
end
......
......@@ -6,6 +6,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca
before do
allow(migration).to receive(:say)
TestEnv.clean_test_path
end
def migration_namespace(namespace)
......
......@@ -3,9 +3,11 @@ require 'spec_helper'
describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :truncate do
let(:migration) { FakeRenameReservedPathMigrationV1.new }
let(:subject) { described_class.new(['the-path'], migration) }
let(:namespace) { create(:group, name: 'the-path') }
before do
allow(migration).to receive(:say)
TestEnv.clean_test_path
end
def migration_namespace(namespace)
......@@ -137,8 +139,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
end
describe "#rename_namespace" do
let(:namespace) { create(:group, name: 'the-path') }
it 'renames paths & routes for the namespace' do
expect(subject).to receive(:rename_path_for_routable)
.with(namespace)
......@@ -149,11 +149,27 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect(namespace.reload.path).to eq('the-path0')
end
it 'tracks the rename' do
expect(subject).to receive(:track_rename)
.with('namespace', 'the-path', 'the-path0')
subject.rename_namespace(namespace)
end
it 'renames things related to the namespace' do
expect(subject).to receive(:rename_namespace_dependencies)
.with(namespace, 'the-path', 'the-path0')
subject.rename_namespace(namespace)
end
end
describe '#rename_namespace_dependencies' do
it "moves the the repository for a project in the namespace" do
create(:project, namespace: namespace, path: "the-path-project")
expected_repo = File.join(TestEnv.repos_path, "the-path0", "the-path-project.git")
subject.rename_namespace(namespace)
subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0')
expect(File.directory?(expected_repo)).to be(true)
end
......@@ -161,13 +177,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
it "moves the uploads for the namespace" do
expect(subject).to receive(:move_uploads).with("the-path", "the-path0")
subject.rename_namespace(namespace)
subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0')
end
it "moves the pages for the namespace" do
expect(subject).to receive(:move_pages).with("the-path", "the-path0")
subject.rename_namespace(namespace)
subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0')
end
it 'invalidates the markdown cache of related projects' do
......@@ -175,13 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect(subject).to receive(:remove_cached_html_for_projects).with([project.id])
subject.rename_namespace(namespace)
subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0')
end
it "doesn't rename users for other namespaces" do
expect(subject).not_to receive(:rename_user)
subject.rename_namespace(namespace)
subject.rename_namespace_dependencies(namespace, 'the-path', 'the-path0')
end
it 'renames the username of a namespace for a user' do
......@@ -189,14 +205,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
expect(subject).to receive(:rename_user).with('the-path', 'the-path0')
subject.rename_namespace(user.namespace)
end
it 'tracks the rename' do
expect(subject).to receive(:track_rename)
.with('namespace', 'the-path', 'the-path0')
subject.rename_namespace(namespace)
subject.rename_namespace_dependencies(user.namespace, 'the-path', 'the-path0')
end
end
......@@ -231,4 +240,43 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
subject.rename_namespaces(type: :child)
end
end
describe '#revert_renames', redis: true do
it 'renames the routes back to the previous values' do
project = create(:project, path: 'a-project', namespace: namespace)
subject.rename_namespace(namespace)
expect(subject).to receive(:perform_rename)
.with(
kind_of(Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Namespace),
'the-path0',
'the-path'
).and_call_original
subject.revert_renames
expect(namespace.reload.path).to eq('the-path')
expect(namespace.reload.route.path).to eq('the-path')
expect(project.reload.route.path).to eq('the-path/a-project')
end
it 'moves the repositories back to their original place' do
project = create(:project, path: 'a-project', namespace: namespace)
project.create_repository
subject.rename_namespace(namespace)
expected_path = File.join(TestEnv.repos_path, 'the-path', 'a-project.git')
expect(subject).to receive(:rename_namespace_dependencies)
.with(
kind_of(Gitlab::Database::RenameReservedPathsMigration::V1::MigrationClasses::Namespace),
'the-path0',
'the-path'
).and_call_original
subject.revert_renames
expect(File.directory?(expected_path)).to be_truthy
end
end
end
......@@ -9,9 +9,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr
namespace: create(:namespace, path: 'known-parent' ))
end
before do
allow(migration).to receive(:say)
TestEnv.clean_test_path
end
describe '#projects_for_paths' do
......
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