Skip to content

Instantly share code, notes, and snippets.

@brenodamata
Created March 15, 2019 19:16
Show Gist options
  • Save brenodamata/24edbf288fe9801b18f50b995e6caa02 to your computer and use it in GitHub Desktop.
Save brenodamata/24edbf288fe9801b18f50b995e6caa02 to your computer and use it in GitHub Desktop.
List record count for all tables
class DatabaseReport
def entry_counts
table_model_names.map do |model_name|
entity = model_name.constantize rescue nil
next if entity.nil?
{ entity.to_s => entity.count }
end.compact
end
private
def table_model_names
ActiveRecord::Base.connection.tables.map(&:singularize).map(&:camelize)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment