2018-11-29 11:08:14 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Shardable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
belongs_to :shard
|
2020-10-06 11:08:33 -04:00
|
|
|
|
|
|
|
scope :for_repository_storage, -> (repository_storage) { joins(:shard).where(shards: { name: repository_storage }) }
|
|
|
|
scope :excluding_repository_storage, -> (repository_storage) { joins(:shard).where.not(shards: { name: repository_storage }) }
|
2020-11-26 07:09:48 -05:00
|
|
|
scope :for_shard, -> (shard) { where(shard_id: shard) }
|
2020-10-06 11:08:33 -04:00
|
|
|
|
2018-11-29 11:08:14 -05:00
|
|
|
validates :shard, presence: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def shard_name
|
|
|
|
shard&.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def shard_name=(name)
|
|
|
|
self.shard = Shard.by_name(name)
|
|
|
|
end
|
|
|
|
end
|