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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/database/dictionary.rb')
-rw-r--r--lib/gitlab/database/dictionary.rb112
1 files changed, 77 insertions, 35 deletions
diff --git a/lib/gitlab/database/dictionary.rb b/lib/gitlab/database/dictionary.rb
index 7b0c8560a26..4ef392a4e44 100644
--- a/lib/gitlab/database/dictionary.rb
+++ b/lib/gitlab/database/dictionary.rb
@@ -3,57 +3,99 @@
module Gitlab
module Database
class Dictionary
- def initialize(file_path)
- @file_path = file_path
- @data = YAML.load_file(file_path)
+ def self.entries(scope = '')
+ @entries ||= {}
+ @entries[scope] ||= Dir.glob(dictionary_path_globs(scope)).map do |file_path|
+ dictionary = Entry.new(file_path)
+ dictionary.validate!
+ dictionary
+ end
end
- def name_and_schema
- [key_name, gitlab_schema.to_sym]
+ def self.entry(name, scope = '')
+ entries(scope).find do |entry|
+ entry.key_name == name
+ end
end
- def table_name
- data['table_name']
+ private_class_method def self.dictionary_path_globs(scope)
+ dictionary_paths.map { |path| Rails.root.join(path, scope, '*.yml') }
end
- def view_name
- data['view_name']
+ private_class_method def self.dictionary_paths
+ ::Gitlab::Database.all_database_connections
+ .values.map(&:db_docs_dir).uniq
end
- def milestone
- data['milestone']
- end
+ class Entry
+ def initialize(file_path)
+ @file_path = file_path
+ @data = YAML.load_file(file_path)
+ end
- def gitlab_schema
- data['gitlab_schema']
- end
+ def name_and_schema
+ [key_name, gitlab_schema.to_sym]
+ end
- def schema?(schema_name)
- gitlab_schema == schema_name.to_s
- end
+ def table_name
+ data['table_name']
+ end
- def key_name
- table_name || view_name
- end
+ def feature_categories
+ data['feature_categories']
+ end
- def validate!
- return true unless gitlab_schema.nil?
+ def view_name
+ data['view_name']
+ end
- raise(
- GitlabSchema::UnknownSchemaError,
- "#{file_path} must specify a valid gitlab_schema for #{key_name}. " \
- "See #{help_page_url}"
- )
- end
+ def milestone
+ data['milestone']
+ end
+
+ def gitlab_schema
+ data['gitlab_schema']
+ end
+
+ def sharding_key
+ data['sharding_key']
+ end
+
+ def desired_sharding_key
+ data['desired_sharding_key']
+ end
+
+ def classes
+ data['classes']
+ end
+
+ def schema?(schema_name)
+ gitlab_schema == schema_name.to_s
+ end
+
+ def key_name
+ table_name || view_name
+ end
+
+ def validate!
+ return true unless gitlab_schema.nil?
+
+ raise(
+ GitlabSchema::UnknownSchemaError,
+ "#{file_path} must specify a valid gitlab_schema for #{key_name}. " \
+ "See #{help_page_url}"
+ )
+ end
- private
+ private
- attr_reader :file_path, :data
+ attr_reader :file_path, :data
- def help_page_url
- # rubocop:disable Gitlab/DocUrl -- link directly to docs.gitlab.com, always
- 'https://docs.gitlab.com/ee/development/database/database_dictionary.html'
- # rubocop:enable Gitlab/DocUrl
+ def help_page_url
+ # rubocop:disable Gitlab/DocUrl -- link directly to docs.gitlab.com, always
+ 'https://docs.gitlab.com/ee/development/database/database_dictionary.html'
+ # rubocop:enable Gitlab/DocUrl
+ end
end
end
end