Skip to content

Instantly share code, notes, and snippets.

View hopewise's full-sized avatar

Samir Sabri hopewise

View GitHub Profile
@hopewise
hopewise / list_tables.rb
Last active February 23, 2023 08:53 — forked from davidleandro/list_tables.rb
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