Class: Partitioned::MultiLevel::Configurator::Reader

Inherits:
PartitionedBase::Configurator::Reader show all
Defined in:
lib/partitioned/multi_level/configurator/reader.rb

Overview

coalesces and parses all Data objects allowing the PartitionManager to request partitioning information froma centralized source from multi level partitioned models

Defined Under Namespace

Classes: UsingConfigurator

Instance Attribute Summary

Attributes inherited from PartitionedBase::Configurator::Reader

#model

Instance Method Summary collapse

Methods inherited from PartitionedBase::Configurator::Reader

#janitorial_archives_needed, #janitorial_creates_needed, #janitorial_drops_needed, #last_partitions_order_by_clause, #name_prefix, #part_name, #run_after_partition_table_create_hooks, #schema_name, #table_alias_name, #table_name

Constructor Details

#initialize(most_derived_activerecord_class) ⇒ Reader

Returns a new instance of Reader.



15
16
17
18
19
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 15

def initialize(most_derived_activerecord_class)
  super
  @using_classes = nil
  @using_configurators = nil
end

Instance Method Details

#base_collectObject



10
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 10

alias :base_collect :collect

#base_collect_from_collectionObject



9
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 9

alias :base_collect_from_collection :collect_from_collection

#base_name(*partition_key_values) ⇒ Object

The name of the child table without the schema name or name prefix.



106
107
108
109
110
111
112
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 106

def base_name(*partition_key_values)
  parts = []
  partition_key_values.each_with_index do |value,index|
    parts << using_configurator(index).base_name(value)
  end
  return parts.join('_')
end

#check_constraint(*partition_key_values) ⇒ Object

Define the check constraint for a given child table.



68
69
70
71
72
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 68

def check_constraint(*partition_key_values)
  index = partition_key_values.length - 1
  value = partition_key_values[index]
  return using_configurator(index).check_constraint(value)
end

#foreign_keys(*partition_key_values) ⇒ Object

Foreign keys to create on each leaf partition.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 88

def foreign_keys(*partition_key_values)
  set = Set.new
  partition_key_values.each_with_index do |key_value, index|
    set.merge(using_configurator(index).foreign_keys(key_value))
  end
  base_collect_from_collection(*partition_key_values, &:foreign_keys).inject(set) do |set, new_items|
    if new_items.is_a? Array
      set += new_items
    else
      set += [new_items]
    end
    set
  end
end

#indexes(*partition_key_values) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 74

def indexes(*partition_key_values)
  bag = {}
  partition_key_values.each_with_index do |key_value, index|
    bag.merge!(using_configurator(index).indexes(key_value))
  end
  base_collect_from_collection(*partition_key_values, &:indexes).inject(bag) do |bag, data_index|
    bag[data_index.field] = (data_index.options || {}) unless data_index.blank?
    bag
  end
end

#on_fieldsArray<Symbol>

The field used to partition child tables.

Returns:

  • (Array<Symbol>)

    fields used to partition this model



25
26
27
28
29
30
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 25

def on_fields
  unless @on_fields
    @on_fields = collect(&:on_field).map(&:to_sym)
  end
  return @on_fields
end

#parent_table_name(*partition_key_values) ⇒ Object

The table name of the table who is the direct ancestor of a child table.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 46

def parent_table_name(*partition_key_values)
  if partition_key_values.length <= 1
    return super
  end

  # [0...-1] is here because the base name for this parent table is defined by the remove the leaf key value
  # that is:
  # current top level table name: public.foos
  # child schema area: foos_partitions
  # current partition classes: ByCompanyId then ByCreatedAt
  # current key values:
  #   company_id: 42
  #   created_at: 2011-01-03
  # child table name: foos_partitions.p42_20110103
  # parent table: foos_partitions.p42
  # grand parent table: public.foos
  return parent_table_schema_name(*partition_key_values) + '.p' + base_name(*partition_key_values[0...-1])
end

#parent_table_schema_name(*partition_key_values) ⇒ Object

The schema name of the table who is the direct ancestor of a child table.



35
36
37
38
39
40
41
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 35

def parent_table_schema_name(*partition_key_values)
  if partition_key_values.length <= 1
    return super
  end

  return schema_name
end

#using_class(index) ⇒ {Partitioned::PartitionedBase}

retrieve a specific partitioning class from an ordered list. for multi-level partitioning we need to find the specific PartitionedBase class for the partitioning level we are interested in managing.

Parameters:

  • index (Integer)

    the partitioning level to query

Returns:



130
131
132
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 130

def using_class(index)
  return using_classes[index]
end

#using_configurator(index) ⇒ Configurator

retrieve a specific configurator from an ordered list. for multi-level partitioning we need to find the specific configurator for the partitioning level we are interested in managing.

Parameters:

  • index (Integer)

    the partitioning level to query

Returns:

  • (Configurator)

    the configurator for the specific level queried



120
121
122
# File 'lib/partitioned/multi_level/configurator/reader.rb', line 120

def using_configurator(index)
  return using_class(index).configurator
end