Skip to content

Instantly share code, notes, and snippets.

@apeckham
Last active August 29, 2015 13:56
Show Gist options
  • Save apeckham/9012817 to your computer and use it in GitHub Desktop.
Save apeckham/9012817 to your computer and use it in GitHub Desktop.
find unused columns: ignore one column at a time and see if tests still pass
class ActiveRecord::Base
def self.columns
super.reject do |column|
"#{table_name}.#{column.name}" == ENV['IGNORE_COLUMN']
end
end
end
#sequel
DB.tables.each { |table| DB[table].columns.each { |column| puts "#{table}.#{column}" } }
File.open('../unnecessary-columns.txt', 'w') do |file|
file.sync = true
ARGF.readlines.shuffle.each do |line|
line.chomp!
puts line
file.puts line if system("IGNORE_COLUMN=#{line} bundle exec rspec spec --fail-fast")
end
end
watch "cat unnecessary-columns.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment