Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug Logs #9

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/mysql_rewinder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
meri025 marked this conversation as resolved.
Show resolved Hide resolved
end

def calculate_inserted_tables
Expand Down
8 changes: 6 additions & 2 deletions lib/mysql_rewinder/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]}] the table to be deleted is empty."
meri025 marked this conversation as resolved.
Show resolved Hide resolved
return
end

log_and_execute("SET FOREIGN_KEY_CHECKS = 0;")
log_and_execute(target_tables.map { |table| "DELETE FROM #{table}" }.join(';'))
Expand All @@ -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
Expand Down