Class: PgDice::PgSliceManager

Inherits:
Object
  • Object
show all
Includes:
LogHelper
Defined in:
lib/pgdice/pg_slice_manager.rb

Overview

PgSliceManager is a wrapper around PgSlice

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogHelper

#blank?, log_duration, #squish

Constructor Details

#initialize(logger:, database_url:, pg_slice_executor:, dry_run: false) ⇒ PgSliceManager

Returns a new instance of PgSliceManager.



11
12
13
14
15
16
# File 'lib/pgdice/pg_slice_manager.rb', line 11

def initialize(logger:, database_url:, pg_slice_executor:, dry_run: false)
  @logger = logger
  @database_url = database_url
  @dry_run = dry_run
  @pg_slice_executor = pg_slice_executor
end

Instance Attribute Details

#database_urlObject (readonly)

Returns the value of attribute database_url.



9
10
11
# File 'lib/pgdice/pg_slice_manager.rb', line 9

def database_url
  @database_url
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/pgdice/pg_slice_manager.rb', line 9

def logger
  @logger
end

Instance Method Details

#add_partitions(params = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pgdice/pg_slice_manager.rb', line 46

def add_partitions(params = {})
  table_name = params.fetch(:table_name)
  future_tables = params.fetch(:future, nil)
  future_tables = "--future #{Integer(future_tables)}" if future_tables

  past_tables = params.fetch(:past, nil)
  past_tables = "--past #{Integer(past_tables)}" if past_tables

  intermediate = params.fetch(:intermediate, nil)
  intermediate = '--intermediate' if intermediate.to_s.casecmp('true').zero?

  run_pgslice("add_partitions #{table_name} #{intermediate} #{future_tables} #{past_tables}", params[:dry_run])
end

#analyze(params = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/pgdice/pg_slice_manager.rb', line 33

def analyze(params = {})
  table_name = params.fetch(:table_name)
  swapped = params.fetch(:swapped, '')
  swapped = '--swapped' if swapped.to_s.casecmp('true').zero?

  run_pgslice("analyze #{table_name} #{swapped}", params[:dry_run])
end

#fill(params = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/pgdice/pg_slice_manager.rb', line 25

def fill(params = {})
  table_name = params.fetch(:table_name)
  swapped = params.fetch(:swapped, '')
  swapped = '--swapped' if swapped.to_s.casecmp('true').zero?

  run_pgslice("fill #{table_name} #{swapped}", params[:dry_run])
end

#prep(params = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/pgdice/pg_slice_manager.rb', line 18

def prep(params = {})
  table_name = params.fetch(:table_name)
  column_name = params.fetch(:column_name)
  period = params.fetch(:period)
  run_pgslice("prep #{table_name} #{column_name} #{period}", params[:dry_run])
end

#swap(params = {}) ⇒ Object



41
42
43
44
# File 'lib/pgdice/pg_slice_manager.rb', line 41

def swap(params = {})
  table_name = params.fetch(:table_name)
  run_pgslice("swap #{table_name}", params[:dry_run])
end

#unprep(params = {}) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/pgdice/pg_slice_manager.rb', line 72

def unprep(params = {})
  table_name = params.fetch(:table_name)

  run_pgslice("unprep #{table_name}", params[:dry_run])
rescue PgSliceError => e
  logger.error { "Rescued PgSliceError: #{e}" }
  false
end

#unprep!(params = {}) ⇒ Object



60
61
62
63
64
# File 'lib/pgdice/pg_slice_manager.rb', line 60

def unprep!(params = {})
  table_name = params.fetch(:table_name)

  run_pgslice("unprep #{table_name}", params[:dry_run])
end

#unswap(params = {}) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/pgdice/pg_slice_manager.rb', line 81

def unswap(params = {})
  table_name = params.fetch(:table_name)

  run_pgslice("unswap #{table_name}", params[:dry_run])
rescue PgSliceError => e
  logger.error { "Rescued PgSliceError: #{e}" }
  false
end

#unswap!(params = {}) ⇒ Object



66
67
68
69
70
# File 'lib/pgdice/pg_slice_manager.rb', line 66

def unswap!(params = {})
  table_name = params.fetch(:table_name)

  run_pgslice("unswap #{table_name}", params[:dry_run])
end