debian-mirror-gitlab/app/models/concerns/partitioned_table.rb

22 lines
706 B
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module PartitionedTable
extend ActiveSupport::Concern
class_methods do
attr_reader :partitioning_strategy
PARTITIONING_STRATEGIES = {
2022-01-26 12:08:38 +05:30
monthly: Gitlab::Database::Partitioning::MonthlyStrategy,
2023-05-27 22:25:52 +05:30
sliding_list: Gitlab::Database::Partitioning::SlidingListStrategy,
ci_sliding_list: Gitlab::Database::Partitioning::CiSlidingListStrategy
2020-07-28 23:09:34 +05:30
}.freeze
2021-09-30 23:02:18 +05:30
def partitioned_by(partitioning_key, strategy:, **kwargs)
2020-07-28 23:09:34 +05:30
strategy_class = PARTITIONING_STRATEGIES[strategy.to_sym] || raise(ArgumentError, "Unknown partitioning strategy: #{strategy}")
2021-09-30 23:02:18 +05:30
@partitioning_strategy = strategy_class.new(self, partitioning_key, **kwargs)
2020-07-28 23:09:34 +05:30
end
end
end