Last active
August 29, 2015 13:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Base | |
def self.columns | |
super.reject do |column| | |
"#{table_name}.#{column.name}" == ENV['IGNORE_COLUMN'] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#sequel | |
DB.tables.each { |table| DB[table].columns.each { |column| puts "#{table}.#{column}" } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
watch "cat unnecessary-columns.txt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment