diff options
author | Nick Thomas <nick@gitlab.com> | 2018-10-19 13:17:50 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-11-05 01:30:04 +0000 |
commit | f760c1cd17881c8aef3a33a3b43db54673db8111 (patch) | |
tree | e1ed99cee3bd9bce1b60f2487d967e8187b110c2 /app/models/shard.rb | |
parent | 93846eb152f32e149ef8c24b707fa0a0c0c52714 (diff) | |
download | gitlab-ce-f760c1cd17881c8aef3a33a3b43db54673db8111.tar.gz |
Start tracking shards in the database
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 |