Commit 3e84b633 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Bob Van Landuyt

Track all renames in redis

parent 36ecbb69
......@@ -114,6 +114,11 @@ module Gitlab
end
end
def track_rename(type, old_path, new_path)
key = "rename:#{migration.version}:#{type}"
Gitlab::Redis.with { |redis| redis.lpush(key, [old_path, new_path].to_json) }
end
def file_storage?
CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
end
......
......@@ -26,6 +26,8 @@ module Gitlab
def rename_namespace(namespace)
old_full_path, new_full_path = rename_path_for_routable(namespace)
track_rename('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)
......
......@@ -16,6 +16,8 @@ module Gitlab
def rename_project(project)
old_full_path, new_full_path = rename_path_for_routable(project)
track_rename('project', old_full_path, new_full_path)
move_repository(project, old_full_path, new_full_path)
move_repository(project, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
move_uploads(old_full_path, new_full_path)
......
......@@ -203,4 +203,21 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca
expect(File.exist?(expected_file)).to be(true)
end
end
describe '#track_rename', redis: true do
it 'tracks a rename in redis' do
key = 'rename:20170316163845:namespace'
subject.track_rename('namespace', 'path/to/namespace', 'path/to/renamed')
old_path, new_path = [nil, nil]
Gitlab::Redis.with do |redis|
rename_info = redis.lpop(key)
old_path, new_path = JSON.parse(rename_info)
end
expect(old_path).to eq('path/to/namespace')
expect(new_path).to eq('path/to/renamed')
end
end
end
......@@ -191,6 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
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)
end
end
describe '#rename_user' do
......
......@@ -85,6 +85,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr
subject.rename_project(project)
end
it 'tracks the rename' do
expect(subject).to receive(:track_rename)
.with('project', 'known-parent/the-path', 'known-parent/the-path0')
subject.rename_project(project)
end
end
describe '#move_repository' do
......
class FakeRenameReservedPathMigrationV1 < ActiveRecord::Migration
include Gitlab::Database::RenameReservedPathsMigration::V1
def version
'20170316163845'
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