Skip to content

Instantly share code, notes, and snippets.

@hopewise
Forked from davidleandro/list_tables.rb
Last active February 23, 2023 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hopewise/79e4cf93d121058965c17f3a61fb854f to your computer and use it in GitHub Desktop.
Save hopewise/79e4cf93d121058965c17f3a61fb854f to your computer and use it in GitHub Desktop.
Rails list all tables count
tables = []
ActiveRecord::Base.connection.tables.each do |t|
count = ActiveRecord::Base.connection.exec_query("select count(*) from #{t}").rows[0][0]
puts "#{t}, #{count.to_i}"
tables << [t, count.to_i]
end
tables.sort_by { |t| t[1] }.reverse!
puts "====================="
ap tables
ap ActiveRecord::Base.connection.instance_variable_get(:@config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment