Skip to content

Instantly share code, notes, and snippets.

@CoryFoy
Created January 18, 2015 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoryFoy/6ddfd53af3559151b9b7 to your computer and use it in GitHub Desktop.
Save CoryFoy/6ddfd53af3559151b9b7 to your computer and use it in GitHub Desktop.
See lengths of all varchars for tables in the application
#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