Class: PgPartitioning::PartitioningMaster

Inherits:
Object
  • Object
show all
Includes:
Printer
Defined in:
lib/pg_partitioning/partitioning_master.rb

Constant Summary collapse

MODES =
%w(equal step date).freeze

Constants included from Printer

PgPartitioning::Printer::COLORS

Instance Method Summary collapse

Methods included from Printer

#alert, #info, #message, #print_row, #text_color

Constructor Details

#initialize(table_name, column_name, mode, cond = nil) ⇒ PartitioningMaster

Returns a new instance of PartitioningMaster.



12
13
14
15
16
17
18
19
20
# File 'lib/pg_partitioning/partitioning_master.rb', line 12

def initialize(table_name, column_name, mode, cond=nil)
  @table_name = table_name 
  @column_name = column_name
  @cond = cond
  @sql = ActiveRecord::Base.connection()
  
  klass = "PgPartitioning::Strategies::#{MODES[mode].classify}"
  @strategy = klass.constantize.new(@table_name, @column_name, @cond, @sql)
end

Instance Method Details

#partitioningObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pg_partitioning/partitioning_master.rb', line 22

def partitioning
  @strategy.partitioning!
  
  drop_foreign_keys
  migration
  
  mode = show_value_of('constraint_exclusion')
  if mode != 'partition'
    alert I18n.t('pg_partitioning.messages.partition_mode', current: mode)
  end
  
  info I18n.t 'pg_partitioning.progress.finish'
rescue => e
  alert e.message || I18n.t('pg_partitioning.failure.other')
end