So I have quite old #rails app with #mysql database. From the first look at the db schema I understood that there are quite a lot of useless columns so I wrote a simple #ruby script which uses #activerecord to check all the empty columns.

require 'active_record'

def query table, column
  "select #{table}.#{column.name} from #{table} where #{table}.#{column.name} is not null or #{table}.#{column.name} != '' limit 1"
end

ActiveRecord::Base.establish_connection(
  adapter: 'mysql2',
  database: db_name,
  host: 'localhost',
  username: username,
  pool: 5
)

connection = ActiveRecord::Base.connection

connection.tables.each do |table|
  connection.columns(table).each do |column|
    next if column.name == 'id'

    if ActiveRecord::Base.connection.execute(query table, column).to_a.empty?
      puts "#{table} | #{column.name}"
    end
  end
end

As you can see it just uses two ActiveRecord methods - tables and columns.