Track all renames in redis
This commit is contained in:
parent
36ecbb6934
commit
3e84b6336f
7 changed files with 44 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
class FakeRenameReservedPathMigrationV1 < ActiveRecord::Migration
|
||||
include Gitlab::Database::RenameReservedPathsMigration::V1
|
||||
|
||||
def version
|
||||
'20170316163845'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue