Created
February 1, 2017 10:40
-
-
Save stephenrichards/98570f9988f06918b17eb01aeb9dd2aa to your computer and use it in GitHub Desktop.
Count record in each table in database
This file contains 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
# use as DbCounter.new.run | |
class DbRrecordCounter | |
def initialize | |
@conn = ActiveRecord::Base.connection | |
end | |
def run | |
tables = @conn.tables | |
tables.each do |t| | |
result = @conn.execute("select count(*) from #{t}") | |
rec = result.first | |
puts "#{t}: #{rec['count']}" | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment