Track all renames in redis

This commit is contained in:
Bob Van Landuyt 2017-06-06 12:28:28 +02:00 committed by Bob Van Landuyt
parent 36ecbb6934
commit 3e84b6336f
7 changed files with 44 additions and 0 deletions

View file

@ -114,6 +114,11 @@ module Gitlab
end end
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? def file_storage?
CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
end end

View file

@ -26,6 +26,8 @@ module Gitlab
def rename_namespace(namespace) def rename_namespace(namespace)
old_full_path, new_full_path = rename_path_for_routable(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_repositories(namespace, old_full_path, new_full_path)
move_uploads(old_full_path, new_full_path) move_uploads(old_full_path, new_full_path)
move_pages(old_full_path, new_full_path) move_pages(old_full_path, new_full_path)

View file

@ -16,6 +16,8 @@ module Gitlab
def rename_project(project) def rename_project(project)
old_full_path, new_full_path = rename_path_for_routable(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, new_full_path)
move_repository(project, "#{old_full_path}.wiki", "#{new_full_path}.wiki") move_repository(project, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
move_uploads(old_full_path, new_full_path) move_uploads(old_full_path, new_full_path)

View file

@ -203,4 +203,21 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase, :trunca
expect(File.exist?(expected_file)).to be(true) expect(File.exist?(expected_file)).to be(true)
end end
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 end

View file

@ -191,6 +191,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameNamespaces, :
subject.rename_namespace(user.namespace) subject.rename_namespace(user.namespace)
end end
it 'tracks the rename' do
expect(subject).to receive(:track_rename)
.with('namespace', 'the-path', 'the-path0')
subject.rename_namespace(namespace)
end
end end
describe '#rename_user' do describe '#rename_user' do

View file

@ -85,6 +85,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :tr
subject.rename_project(project) subject.rename_project(project)
end 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 end
describe '#move_repository' do describe '#move_repository' do

View file

@ -1,3 +1,7 @@
class FakeRenameReservedPathMigrationV1 < ActiveRecord::Migration class FakeRenameReservedPathMigrationV1 < ActiveRecord::Migration
include Gitlab::Database::RenameReservedPathsMigration::V1 include Gitlab::Database::RenameReservedPathsMigration::V1
def version
'20170316163845'
end
end end