Welcome to mirror list, hosted at ThFree Co, Russian Federation.

migration_classes.rb « rename_reserved_paths_migration « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9133b97d2391260517c58289e5e5d13bd68e148e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
module Gitlab
  module Database
    module RenameReservedPathsMigration
      module MigrationClasses
        module Routable
          def full_path
            if route && route.path.present?
              @full_path ||= route.path
            else
              update_route if persisted?

              build_full_path
            end
          end

          def build_full_path
            if parent && path
              parent.full_path + '/' + path
            else
              path
            end
          end

          def update_route
            prepare_route
            route.save
          end

          def prepare_route
            route || build_route(source: self)
            route.path = build_full_path
            route.name = build_full_name
            @full_path = nil
            @full_name = nil
          end

          def build_full_name
            if parent && name
              parent.human_name + ' / ' + name
            else
              name
            end
          end

          def human_name
            owner&.name
          end
        end

        class User < ActiveRecord::Base
          self.table_name = 'users'
        end

        class Namespace < ActiveRecord::Base
          include MigrationClasses::Routable
          self.table_name = 'namespaces'
          belongs_to :parent,
                     class_name: "#{MigrationClasses.name}::Namespace"
          has_one :route, as: :source
          has_many :children,
                   class_name: "#{MigrationClasses.name}::Namespace",
                   foreign_key: :parent_id
          belongs_to :owner,
                     class_name: "#{MigrationClasses.name}::User"

          # Overridden to have the correct `source_type` for the `route` relation
          def self.name
            'Namespace'
          end
        end

        class Route < ActiveRecord::Base
          self.table_name = 'routes'
          belongs_to :source, polymorphic: true
        end

        class Project < ActiveRecord::Base
          include MigrationClasses::Routable
          has_one :route, as: :source
          self.table_name = 'projects'

          def repository_storage_path
            Gitlab.config.repositories.storages[repository_storage]['path']
          end

          # Overridden to have the correct `source_type` for the `route` relation
          def self.name
            'Project'
          end
        end
      end
    end
  end
end