Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

postgresql - Select all tables on Heroku Dataclips

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...