Module: PgDice::TableFinder

Includes:
DateHelper
Included in:
PartitionManager, Validation
Defined in:
lib/pgdice/table_finder.rb

Overview

Module which is a collection of methods used by PartitionManager to find and list tables

Instance Method Summary collapse

Methods included from DateHelper

#pad_date, #safe_date_builder, #truncate_date

Instance Method Details

#batched_tables(tables, batch_size) ⇒ Object



19
20
21
# File 'lib/pgdice/table_finder.rb', line 19

def batched_tables(tables, batch_size)
  tables.first(batch_size)
end

#find_droppable_partitions(all_tables, older_than, minimum_tables, period) ⇒ Object



8
9
10
11
12
# File 'lib/pgdice/table_finder.rb', line 8

def find_droppable_partitions(all_tables, older_than, minimum_tables, period)
  tables_older_than = tables_older_than(all_tables, older_than, period)
  tables_to_grab = tables_to_grab(tables_older_than.size, minimum_tables)
  tables_older_than.first(tables_to_grab)
end

#table_tester(tables, predicate) ⇒ Object



35
36
37
38
39
# File 'lib/pgdice/table_finder.rb', line 35

def table_tester(tables, predicate)
  tables.select do |partition_name|
    predicate.call(safe_date_builder(partition_name))
  end
end

#tables_newer_than(tables, newer_than, period) ⇒ Object



29
30
31
32
33
# File 'lib/pgdice/table_finder.rb', line 29

def tables_newer_than(tables, newer_than, period)
  table_tester(tables, lambda do |partition_created_at_time|
    partition_created_at_time > truncate_date(newer_than.to_date, period)
  end)
end

#tables_older_than(tables, older_than, period) ⇒ Object



23
24
25
26
27
# File 'lib/pgdice/table_finder.rb', line 23

def tables_older_than(tables, older_than, period)
  table_tester(tables, lambda do |partition_created_at_time|
    partition_created_at_time < truncate_date(older_than.to_date, period)
  end)
end

#tables_to_grab(eligible_tables, minimum_tables) ⇒ Object



14
15
16
17
# File 'lib/pgdice/table_finder.rb', line 14

def tables_to_grab(eligible_tables, minimum_tables)
  tables_to_grab = eligible_tables - minimum_tables
  tables_to_grab.positive? ? tables_to_grab : 0
end