Created
January 18, 2015 23:42
-
-
Save CoryFoy/6ddfd53af3559151b9b7 to your computer and use it in GitHub Desktop.
See lengths of all varchars for tables in the application
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
#You can use this from a rails console by creating this | |
#in a directory, starting up rails c, and then doing a | |
#'load fields.rb'. Then just call Fields.show_report | |
class Fields | |
def self.show_report | |
Rails.application.eager_load! | |
ActiveRecord::Base.descendants.each do |model| | |
table_name = model.table_name | |
puts "Varchar length report for #{table_name}" | |
puts "-------------------------------------------------" | |
puts "" | |
begin | |
model.columns.each do |col| | |
puts " #{col.name}: #{col.limit}" if col.type == :string | |
end | |
rescue | |
puts "Table not valid" | |
end | |
puts "" | |
puts "" | |
end | |
puts "-------------------------------------------------" | |
puts "END OF REPORT" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment