Class: Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects

Inherits:
RenameBase
  • Object
show all
Includes:
ShellAdapter
Defined in:
lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb

Instance Attribute Summary

Attributes inherited from RenameBase

#migration, #paths

Instance Method Summary collapse

Methods included from ShellAdapter

#gitlab_shell

Methods inherited from RenameBase

#file_storage?, #initialize, #join_routable_path, #move_folders, #move_pages, #move_uploads, #pages_dir, #path_patterns, #perform_rename, #redis_key_for_type, #remove_cached_html_for_projects, #remove_last_occurrence, #rename_path, #rename_path_for_routable, #rename_routes, #reverts_for_type, #route_exists?, #track_rename, #uploads_dir

Constructor Details

This class inherits a constructor from Gitlab::Database::RenameReservedPathsMigration::V1::RenameBase

Instance Method Details

#move_project_folders(project, old_full_path, new_full_path) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb', line 26

def move_project_folders(project, old_full_path, new_full_path)
  unless project.hashed_storage?(:repository)
    move_repository(project, old_full_path, new_full_path)
    move_repository(project, "#{old_full_path}.wiki", "#{new_full_path}.wiki")
  end

  move_uploads(old_full_path, new_full_path) unless project.hashed_storage?(:attachments)
  move_pages(old_full_path, new_full_path)
end

#move_repository(project, old_path, new_path) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb', line 57

def move_repository(project, old_path, new_path)
  unless gitlab_shell.mv_repository(project.repository_storage,
                                    old_path,
                                    new_path)
    Gitlab::AppLogger.error "Error moving #{old_path} to #{new_path}"
  end
end

#projects_for_pathsObject



65
66
67
68
69
70
71
72
73
# File 'lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb', line 65

def projects_for_paths
  return @projects_for_paths if @projects_for_paths

  with_paths = MigrationClasses::Route.arel_table[:path]
                 .matches_any(path_patterns)

  @projects_for_paths = MigrationClasses::Project.joins(:route).where(with_paths)
    .allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/421843')
end

#rename_project(project) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb', line 18

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_project_folders(project, old_full_path, new_full_path)
end

#rename_projectsObject



10
11
12
13
14
15
16
# File 'lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb', line 10

def rename_projects
  projects_for_paths.each do |project|
    rename_project(project)
  end

  remove_cached_html_for_projects(projects_for_paths.map(&:id))
end

#revert_renamesObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitlab/database/rename_reserved_paths_migration/v1/rename_projects.rb', line 36

def revert_renames
  reverts_for_type('project') do |path_before_rename, current_path|
    matches_path = MigrationClasses::Route.arel_table[:path].matches(current_path)
    project = MigrationClasses::Project.joins(:route)
                .allow_cross_joins_across_databases(url:
                  'https://gitlab.com/gitlab-org/gitlab/-/issues/421843')
                .find_by(matches_path)

    if project
      perform_rename(project, current_path, path_before_rename)

      move_project_folders(project, current_path, path_before_rename)
    else
      say "Couldn't rename project from #{current_path} back to "\
          "#{path_before_rename}, project was renamed or no longer "\
          "exists at the expected path."

    end
  end
end