Skip to content

Instantly share code, notes, and snippets.

@caioagiani
Last active March 30, 2023 16:35
Show Gist options
  • Save caioagiani/88d50616627f4ba5110580d3a285e6e1 to your computer and use it in GitHub Desktop.
Save caioagiani/88d50616627f4ba5110580d3a285e6e1 to your computer and use it in GitHub Desktop.
tables_and_columns = []
ActiveRecord::Base.connection.tables.count
ActiveRecord::Base.connection.tables.each do |table_name|
count = ActiveRecord::Base.connection.columns(table_name).count
tables_and_columns << { table_name: table_name, column_count: count }
end
tables_and_columns.sort_by! { |tc| tc[:table_name] }
tables_and_columns.each { |tc| puts "#{tc[:table_name]}, #{tc[:column_count]}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment