Created
January 6, 2016 20:08
-
-
Save maxjustus/dd15d585ea32ba19cb7c to your computer and use it in GitHub Desktop.
Little active record extension to make zero downtime column removal a lil more convenient in Rails
This file contains hidden or 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
# Put this in config/initializers | |
module ActiveRecord | |
class Base | |
def self.removed_columns(*names) | |
@@removed_columns = Set.new(names.map(&:to_s)) | |
instance_eval do | |
def columns | |
cols = super | |
cols.reject { |col| @@removed_columns.include?(col.name) } | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or 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 Example < ActiveRecord::Base | |
removed_columns :name, :removed | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment