Skip to content

Instantly share code, notes, and snippets.

@bogdan
Last active August 19, 2021 12:17
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 bogdan/540979fbf03bd96960e6415f55fdd123 to your computer and use it in GitHub Desktop.
Save bogdan/540979fbf03bd96960e6415f55fdd123 to your computer and use it in GitHub Desktop.
class TablesStatsGrid < BaseDatagrid
scope do
[]
end
dynamic do
scope do
ActiveRecord::Base.connection.select_all("SHOW TABLE STATUS").to_ary
end
end
self.default_column_options = {order_by_value: true}
filter(:name) do |value, scope|
scope.select{|t| t['Name'].includes?(value)}
end
column(:name) do |asset|
asset['Name']
end
column(:rows) do |asset|
asset['Rows']
end
column(:row_size, header: 'Row Size') do |asset|
asset['Avg_row_length']
end
column(:data_size, header: 'Data Size') do |asset|
format(asset['Data_length']) { |value| number_to_human_size(value) }
end
column(:index_size, header: 'Index Size') do |asset|
format(asset['Index_length']) { |value| number_to_human_size(value) }
end
column(:total_size, header: 'Total Size') do |asset|
asset['Total_length'] = asset['Data_length'].to_i + asset['Index_length'].to_i
format(asset['Total_length']) { |value| number_to_human_size(value) }
end
column(:comment) do |asset|
asset['Comment']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment