Welcome to mirror list, hosted at ThFree Co, Russian Federation.

partitioning.rb « gitlab_patches « active_record « lib « activerecord-gitlab « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf0bd4849e2d71f612383595fc204fbab27cc0f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require_relative "partitioning/associations/builder/association"
require_relative "partitioning/reflection/abstract_reflection"
require_relative "partitioning/reflection/association_reflection"
require_relative "partitioning/reflection/macro_reflection"
require_relative "partitioning/base"

module ActiveRecord
  module GitlabPatches
    # This allows to filter data by a dedicated column for association and joins to ActiveRecord::Base.
    #
    # class ApplicationRecord < ActiveRecord::Base
    #   belongs_to :pipeline,
    #     -> (build) { where(partition_id: build.partition_id) },
    #     partition_foreign_key: :partition_id
    #
    #   To control the join filter
    #   def self.use_partition_id_filter?
    #     Feature.enabled?(...)
    #   end
    # end
    module Partitioning
      ActiveSupport.on_load(:active_record) do
        ::ActiveRecord::Associations::Builder::Association.prepend(
          ActiveRecord::GitlabPatches::Partitioning::Associations::Builder::Association
        )
        ::ActiveRecord::Reflection::AbstractReflection.prepend(
          ActiveRecord::GitlabPatches::Partitioning::Reflection::AbstractReflection
        )
        ::ActiveRecord::Reflection::AssociationReflection.prepend(
          ActiveRecord::GitlabPatches::Partitioning::Reflection::AssociationReflection
        )
        ::ActiveRecord::Reflection::MacroReflection.prepend(
          ActiveRecord::GitlabPatches::Partitioning::Reflection::MacroReflection
        )
        ::ActiveRecord::Base.prepend(
          ActiveRecord::GitlabPatches::Partitioning::Base
        )
      end
    end
  end
end