Created
December 7, 2012 22:56
-
-
Save oggy/4237218 to your computer and use it in GitHub Desktop.
Make ActiveRecord ignore columns, so you can drop them without downtime.
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
ActiveRecord::Base.class_eval do | |
def self.ignore_columns(*names) | |
extend ColumnIgnorance | |
ignored_columns.merge names.map(&:to_s) | |
end | |
module ColumnIgnorance | |
def columns | |
return @columns if @columns | |
@columns = super.reject do |column| | |
ignored_columns.include?(column.name) | |
end | |
end | |
def ignored_columns | |
@ignored_columns ||= Set[] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment