Skip to content

Instantly share code, notes, and snippets.

@CoryFoy
Created January 18, 2015 23:42
Show Gist options
  • Select an option

  • Save CoryFoy/6ddfd53af3559151b9b7 to your computer and use it in GitHub Desktop.

Select an option

Save CoryFoy/6ddfd53af3559151b9b7 to your computer and use it in GitHub Desktop.

Revisions

  1. CoryFoy created this gist Jan 18, 2015.
    25 changes: 25 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #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