How can I display the current record counts from all my database tables in one command using the console? Thanks!
This will do it if you've 'touched' all your classes, but only for actual models:
ActiveRecord::Base.subclasses.map { |c| "#{c.name} => #{c.count}" }
If you really want all tables, including join tables that don't map to models:
ActiveRecord::Base.connection.tables.map { |t| "#{t} => " + ActiveRecord::Base.connection.execute("select count(*) from #{t}").fetch_row.first}
ActiveRecord::Base.connection.tables
this will return an array of the tables you have, if you find it useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With