Skip to content

Instantly share code, notes, and snippets.

@MyklClason
Last active April 5, 2018 00:10
Show Gist options
  • Save MyklClason/fdce6e48274f669d71b3233b4fc534e9 to your computer and use it in GitHub Desktop.
Save MyklClason/fdce6e48274f669d71b3233b4fc534e9 to your computer and use it in GitHub Desktop.
Get counts of all model records in the database via Ruby code (can be used in the console). Useful for determining what's using up heroku database row limits.
Rails.application.eager_load!
ActiveRecord::Base.descendants.map { |m| [m.name, m.all.size] }.sort_by { |m, s| -s }
# Print on seperate lines
# puts ActiveRecord::Base.descendants.map { |m| [m.name, m.all.size] }.sort_by { |m, s| -s }.map(&:inspect)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment