diff options
author | Nick Thomas <nick@gitlab.com> | 2018-10-19 15:17:50 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-11-05 04:30:04 +0300 |
commit | f760c1cd17881c8aef3a33a3b43db54673db8111 (patch) | |
tree | e1ed99cee3bd9bce1b60f2487d967e8187b110c2 /app/models | |
parent | 93846eb152f32e149ef8c24b707fa0a0c0c52714 (diff) |
Start tracking shards in the database
Diffstat (limited to 'app/models')
-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 |