diff --git a/lib/mysql_rewinder.rb b/lib/mysql_rewinder.rb index ae9196c..b5f61c8 100644 --- a/lib/mysql_rewinder.rb +++ b/lib/mysql_rewinder.rb @@ -56,7 +56,10 @@ def reset_inserted_tables end @inserted_tables = Set.new - FileUtils.rm(Dir.glob(@inserted_table_record_dir.join("#{@initialized_pid}.*.inserted_tables").to_s)) + files = Dir.glob(@inserted_table_record_dir.join("#{@initialized_pid}.*.inserted_tables").to_s) + + FileUtils.rm(files) + @logger&.debug { "[MysqlRewinder] removed files: #{files.join(', ')}" } if files.any? end def calculate_inserted_tables diff --git a/lib/mysql_rewinder/cleaner.rb b/lib/mysql_rewinder/cleaner.rb index e9a449a..aec37a1 100644 --- a/lib/mysql_rewinder/cleaner.rb +++ b/lib/mysql_rewinder/cleaner.rb @@ -19,7 +19,11 @@ def clean_all def clean(tables:) target_tables = (tables - @except_tables) & all_tables - return if target_tables.empty? + + if target_tables.empty? + @logger&.debug { "[MysqlRewinder][#{@db_config[:database]}] Skip DELETE query because target_table is empty." } + return + end log_and_execute("SET FOREIGN_KEY_CHECKS = 0;") log_and_execute(target_tables.map { |table| "DELETE FROM #{table}" }.join(';')) @@ -42,7 +46,7 @@ def log_and_execute(sql) res = @client.execute(sql) duration = (Time.now - start_ts) * 1000 - name = "[MysqlRewinder] Cleaner SQL (#{duration.round(1)}ms)" + name = "[MysqlRewinder][#{@db_config[:database]}] Cleaner SQL (#{duration.round(1)}ms)" msg = "\e[1m\e[30m#{name}\e[0m \e[34m#{sql}\e[0m" @logger.debug msg res