class Lhm::Cleanup::Current
Attributes
connection[R]
ddls[R]
run[R]
Public Class Methods
new(run, origin_table_name, connection, options = {})
click to toggle source
# File lib/lhm/cleanup/current.rb, line 7 def initialize(run, origin_table_name, connection, options = {}) @run = run @table_name = TableName.new(origin_table_name) @connection = connection @ddls = [] @retry_helper = SqlRetry.new( @connection, { log_prefix: "Cleanup::Current" }.merge!(options.fetch(:retriable, {})) ) end
Public Instance Methods
execute()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 22 def execute build_statements_for_drop_lhm_triggers_for_origin build_statements_for_rename_lhmn_tables_for_origin if run execute_ddls else report_ddls end end
Private Instance Methods
all_triggers_for_origin()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 44 def all_triggers_for_origin @all_triggers_for_origin ||= connection.select_values("show triggers like '%#{@table_name.original}'").collect do |trigger| trigger.respond_to?(:trigger) ? trigger.trigger : trigger end end
build_statements_for_drop_lhm_triggers_for_origin()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 34 def build_statements_for_drop_lhm_triggers_for_origin lhm_triggers_for_origin.each do |trigger| @ddls << "drop trigger if exists #{trigger}" end end
build_statements_for_rename_lhmn_tables_for_origin()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 50 def build_statements_for_rename_lhmn_tables_for_origin lhmn_tables_for_origin.each do |table| @ddls << "rename table #{table} to #{@table_name.failed}" end end
execute_ddls()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 60 def execute_ddls ddls.each do |ddl| @retry_helper.with_retries do |retriable_connection| retriable_connection.execute(ddl) end end end
lhm_triggers_for_origin()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 40 def lhm_triggers_for_origin @lhm_triggers_for_origin ||= all_triggers_for_origin.select { |name| name =~ /^lhmt/ } end
lhmn_tables_for_origin()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 56 def lhmn_tables_for_origin @lhmn_tables_for_origin ||= connection.select_values("show tables like '#{@table_name.new}'") end
report_ddls()
click to toggle source
# File lib/lhm/cleanup/current.rb, line 68 def report_ddls puts "The following DDLs would be executed:" ddls.each { |ddl| puts ddl } end