Skip to content

Instantly share code, notes, and snippets.

@sshaw
Last active July 29, 2023 17:15
Show Gist options
  • Save sshaw/1d860c13d9b22c8e27a954e109072ad6 to your computer and use it in GitHub Desktop.
Save sshaw/1d860c13d9b22c8e27a954e109072ad6 to your computer and use it in GitHub Desktop.
Rails: Print What Models Have Ignored Columns That No Longer Exist in DB (Moved: https://github.com/sshaw/ignored_columns_tasks)
(ApplicationRecord.subclasses + ActiveRecord::Base.subclasses).each do |klass|
next if klass.abstract_class? || klass.ignored_columns.none?
ignored = klass.ignored_columns
klass.ignored_columns = []
klass.reset_column_information
removed = ignored - klass.column_names
klass.ignored_columns = ignored
next unless removed.any?
printf "%s: %s\n", klass.name, removed.to_sentence
end
@sshaw
Copy link
Author

sshaw commented Jul 28, 2023

rails r print-non-existant-ignored-columns.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment