Select all tables on Heroku Dataclips

Viewed 47

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:

  1. connects to the database
  2. List All the tables
  3. Gets the count of records in each table
  4. outputs results

But I want to be able to do the same thing on a heroku dataclip

0 Answers
Related