Skip to content

Instantly share code, notes, and snippets.

@maxjustus
Created January 6, 2016 20:08
Show Gist options
  • Save maxjustus/dd15d585ea32ba19cb7c to your computer and use it in GitHub Desktop.
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
# 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
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