I have a script that I can run on my console
namespace :maintenance do
desc "List tables by record count"
task :list_table_by_count => :environment do
results = []
ActiveRecord::Base.connection.tables.sort.each do |table_name|
count = ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM #{table_name};")[0]["count"]
results << {table: table_name, count: count}
end
results = results.sort_by { |hsh| hsh[:count] }
puts results
end
So this scripts:
- connects to the database
- List All the tables
- Gets the count of records in each table
- outputs results
But I want to be able to do the same thing on a heroku dataclip
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…