Skip to content

Instantly share code, notes, and snippets.

@davidleandro
Last active February 23, 2023 08:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save davidleandro/1e6e457a04d306a7d7a8c098fa1ae613 to your computer and use it in GitHub Desktop.
Save davidleandro/1e6e457a04d306a7d7a8c098fa1ae613 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]
tables << [t, count.to_i]
end
tables.sort_by { |t| t[1] }.reverse!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment