1# frozen_string_literal: true
2
3# This module can be included in migrations to make it easier to rename paths
4# of `Namespace` & `Project` models certain paths would become `reserved`.
5#
6# If the way things are stored on the filesystem related to namespaces and
7# projects ever changes. Don't update this module, or anything nested in `V1`,
8# since it needs to keep functioning for all migrations using it using the state
9# that the data is in at the time. Instead, create a `V2` module that implements
10# the new way of reserving paths.
11module Gitlab
12  module Database
13    module RenameReservedPathsMigration
14      module V1
15        def self.included(kls)
16          kls.include(MigrationHelpers)
17        end
18
19        def rename_wildcard_paths(one_or_more_paths)
20          rename_child_paths(one_or_more_paths)
21          paths = Array(one_or_more_paths)
22          RenameProjects.new(paths, self).rename_projects
23        end
24
25        def rename_child_paths(one_or_more_paths)
26          paths = Array(one_or_more_paths)
27          RenameNamespaces.new(paths, self).rename_namespaces(type: :child)
28        end
29
30        def rename_root_paths(paths)
31          paths = Array(paths)
32          RenameNamespaces.new(paths, self).rename_namespaces(type: :top_level)
33        end
34
35        def revert_renames
36          RenameProjects.new([], self).revert_renames
37          RenameNamespaces.new([], self).revert_renames
38        end
39      end
40    end
41  end
42end
43