This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Warn if an auto_increment column is reaching max value limit" | |
task check_auto_increment_columns_overflow: :environment do | |
threshold_percent = (ENV["THRESHOLD"] || "90").to_i | |
ActiveRecord::Base.connection.tables.each do |table| | |
ActiveRecord::Base.connection.columns(table).each do |column| | |
next unless column.type == :integer && column.extra.to_s =~ /auto_increment/ | |
auto_increment = ActiveRecord::Base.connection.select_one("SHOW TABLE STATUS LIKE '#{table}'")["Auto_increment"] | |
max_value = column.cast_type.send(:max_value) |
NewerOlder