blob: 0c8a248b984fe9a9ca643426e810b245fc4c7d97 (
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
47
48
49
|
# frozen_string_literal: true
if ::ActiveRecord::VERSION::STRING >= "7.1"
raise 'New version of active-record detected, please remove or update this patch'
end
module ActiveRecord
module GitlabPatches
module Partitioning
module Base
extend ActiveSupport::Concern
def _query_constraints_hash
constraints_hash = super
return constraints_hash unless self.class.use_partition_id_filter?
if self.class.query_constraints_list.nil?
{ @primary_key => id_in_database } # rubocop:disable Gitlab/ModuleWithInstanceVariables
else
self.class.query_constraints_list.index_with do |column_name|
attribute_in_database(column_name)
end
end
end
class_methods do
def use_partition_id_filter?
false
end
def query_constraints(*columns_list)
raise ArgumentError, "You must specify at least one column to be used in querying" if columns_list.empty?
@query_constraints_list = columns_list.map(&:to_s)
end
def query_constraints_list # :nodoc:
@query_constraints_list ||= if base_class? || primary_key != base_class.primary_key
primary_key if primary_key.is_a?(Array)
else
base_class.query_constraints_list
end
end
end
end
end
end
end
|