diff options
6 files changed, 38 insertions, 9 deletions
diff --git a/db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb b/db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb index 73a59ef0d74..88eca39c716 100644 --- a/db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb +++ b/db/post_migrate/20170412174900_rename_reserved_dynamic_paths.rb @@ -27,7 +27,8 @@ class RenameReservedDynamicPaths < ActiveRecord::Migration users ] - DISALLOWED_WILDCARD_PATHS = %w[objects folders file] + DISALLOWED_WILDCARD_PATHS = %w[info/lfs/objects gitlab-lfs/objects + environments/folders] def up rename_root_paths(DISALLOWED_ROOT_PATHS) diff --git a/lib/gitlab/database/rename_reserved_paths_migration/rename_base.rb b/lib/gitlab/database/rename_reserved_paths_migration/rename_base.rb index 367348a9a42..4d454fd8ea0 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/rename_base.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/rename_base.rb @@ -13,6 +13,10 @@ module Gitlab @migration = migration end + def path_patterns + @path_patterns ||= paths.map { |path| "%#{path}" } + end + def rename_path_for_routable(routable) old_path = routable.path old_full_path = routable.full_path diff --git a/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb b/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb index 80e8135ea93..847b6e56955 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces.rb @@ -16,9 +16,9 @@ module Gitlab elsif type == :top_level MigrationClasses::Namespace.where(parent_id: nil) end - with_paths = MigrationClasses::Namespace.arel_table[:path]. - matches_any(paths) - namespaces.where(with_paths) + with_paths = MigrationClasses::Route.arel_table[:path]. + matches_any(path_patterns) + namespaces.joins(:route).where(with_paths) end def rename_namespace(namespace) @@ -43,8 +43,8 @@ module Gitlab end def repo_paths_for_namespace(namespace) - projects_for_namespace(namespace). - select('distinct(repository_storage)').map(&:repository_storage_path) + projects_for_namespace(namespace).distinct.select(:repository_storage). + map(&:repository_storage_path) end def projects_for_namespace(namespace) diff --git a/lib/gitlab/database/rename_reserved_paths_migration/rename_projects.rb b/lib/gitlab/database/rename_reserved_paths_migration/rename_projects.rb index 02f10d8e951..49b9453b134 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/rename_projects.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/rename_projects.rb @@ -28,9 +28,10 @@ module Gitlab end def projects_for_paths - with_paths = MigrationClasses::Project.arel_table[:path] - .matches_any(paths) - MigrationClasses::Project.where(with_paths) + with_paths = MigrationClasses::Route.arel_table[:path] + .matches_any(path_patterns) + + MigrationClasses::Project.joins(:route).where(with_paths) end end end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces_spec.rb index ee481e4610c..00d6cf0105c 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_namespaces_spec.rb @@ -14,6 +14,19 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameNamespaces do end describe '#namespaces_for_paths' do + context 'nested namespaces' do + let(:subject) { described_class.new(['parent/the-Path'], migration) } + + it 'includes the namespace' do + parent = create(:namespace, path: 'parent') + child = create(:namespace, path: 'the-path', parent: parent) + + found_ids = subject.namespaces_for_paths(type: :wildcard). + map(&:id) + expect(found_ids).to contain_exactly(child.id) + end + end + context 'for wildcard namespaces' do it 'only returns child namespaces with the correct path' do _root_namespace = create(:namespace, path: 'THE-path') diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_projects_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_projects_spec.rb index 4a572133b69..173ebecb676 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_projects_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/rename_projects_spec.rb @@ -9,6 +9,16 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameProjects do end describe '#projects_for_paths' do + it 'searches using nested paths' do + namespace = create(:namespace, path: 'hello') + project = create(:empty_project, path: 'THE-path', namespace: namespace) + + result_ids = described_class.new(['Hello/the-path'], migration). + projects_for_paths.map(&:id) + + expect(result_ids).to contain_exactly(project.id) + end + it 'includes the correct projects' do project = create(:empty_project, path: 'THE-path') _other_project = create(:empty_project) |