Skip to content

Instantly share code, notes, and snippets.

@stephenrichards
Created February 1, 2017 10:40
Show Gist options
  • Save stephenrichards/98570f9988f06918b17eb01aeb9dd2aa to your computer and use it in GitHub Desktop.
Save stephenrichards/98570f9988f06918b17eb01aeb9dd2aa to your computer and use it in GitHub Desktop.
Count record in each table in database
# 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