diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-11-06 15:43:24 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-11-06 15:43:24 +0000 |
commit | 1208d55206128266690f46f0165df0fc10c24941 (patch) | |
tree | 93fbdde5a5db6cdd8f79f2806707dab093985aa2 /app/models/shard.rb | |
parent | d171ff60168cd55b6d7b9ee920269f44a26e577e (diff) | |
parent | d0c58a97c8a053c0beec7c13c1c6ec5042120ef1 (diff) | |
download | gitlab-ce-1208d55206128266690f46f0165df0fc10c24941.tar.gz |
Merge branch 'master' into 'refactor-snippets-finder'refactor-snippets-finder
# Conflicts:
# spec/models/project_spec.rb
Diffstat (limited to 'app/models/shard.rb')
-rw-r--r-- | app/models/shard.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/app/models/shard.rb b/app/models/shard.rb new file mode 100644 index 00000000000..2fa22bd040c --- /dev/null +++ b/app/models/shard.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class Shard < ActiveRecord::Base + # Store shard names from the configuration file in the database. This is not a + # list of active shards - we just want to assign an immutable, unique ID to + # every shard name for easy indexing / referencing. + def self.populate! + return unless table_exists? + + # The GitLab config does not change for the lifecycle of the process + in_config = Gitlab.config.repositories.storages.keys.map(&:to_s) + + transaction do + in_db = all.pluck(:name) + missing = in_config - in_db + + missing.map { |name| by_name(name) } + end + end + + def self.by_name(name) + find_or_create_by(name: name) + rescue ActiveRecord::RecordNotUnique + retry + end +end |