Created
March 15, 2019 19:16
-
-
Save brenodamata/24edbf288fe9801b18f50b995e6caa02 to your computer and use it in GitHub Desktop.
List record count for all tables
This file contains hidden or 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
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