How to remove column without downtime with ActiveRecord 3.1?
activerecord, ruby, ruby-on-rails, ruby-on-rails-3
Solution
Luke Ludwig of TST Media offers a solution here. Essentially they "override the ActiveRecord::Base.columns method on the class whose column is being removed."
(solution applicable to all but 3.1)
Problem
Removing columns from tables while running application with ActiveRecord causes errors, because ActiveRecord caches column names. Workaround for other versions of ActiveRecord is to override #columns method in the model and filter out deprecated column names before migration (basically - hide these columns from AR). This worked because all column name related methods were based on #columns call In ActiveRecord 3.1 caching of table structures is moved to ConnectionPool, and all column name related values (e.g. coluumns_hash) are cached independently (3.2 uses ModelSchema.columns that made this working again) Is there any way (other than deep-hack of concrete adapters) to achieve safe column drop in ActiveRecord 3.1?