Sha256: ff1b537e5b246c466ed77d82fae3df39fd8fad51f2319df44158c3c51559fb43
Contents?: true
Size: 1.97 KB
Versions: 3
Compression:
Stored size: 1.97 KB
Contents
require 'lhm/timestamp' require 'lhm/sql_retry' module Lhm module Cleanup class Current def initialize(run, origin_table_name, connection, options={}) @run = run @table_name = TableName.new(origin_table_name) @connection = connection @ddls = [] @retry_config = options[:retriable] || {} end attr_reader :run, :connection, :ddls 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 def build_statements_for_drop_lhm_triggers_for_origin lhm_triggers_for_origin.each do |trigger| @ddls << "drop trigger if exists #{trigger}" end end def lhm_triggers_for_origin @lhm_triggers_for_origin ||= all_triggers_for_origin.select { |name| name =~ /^lhmt/ } end 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 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 def lhmn_tables_for_origin @lhmn_tables_for_origin ||= connection.select_values("show tables like '#{@table_name.new}'") end def execute_ddls ddls.each do |ddl| @connection.execute(ddl, should_retry: true, retry_options: @retry_config) end Lhm.logger.info("Dropped triggers on #{@lhm_triggers_for_origin.join(', ')}") Lhm.logger.info("Dropped tables #{@lhm_triggers_for_origin.join(', ')}") end def report_ddls Lhm.logger.info("The following DDLs would be executed: #{ddls}") end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lhm-shopify-3.5.3 | lib/lhm/cleanup/current.rb |
lhm-shopify-3.5.2 | lib/lhm/cleanup/current.rb |
lhm-shopify-3.5.1 | lib/lhm/cleanup/current.rb |