blob: 2f3dde2a871372a8e2cb64738cad024032065bfd (
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
44
45
46
|
# 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::Persistence.prepend(
ActiveRecord::GitlabPatches::Partitioning::Base
)
::ActiveRecord::Persistence::ClassMethods.prepend(
ActiveRecord::GitlabPatches::Partitioning::Base::ClassMethods
)
end
end
end
end
|