Skip to content

Instantly share code, notes, and snippets.

@neaf
Created May 31, 2013 10:38
Show Gist options
  • Save neaf/5684177 to your computer and use it in GitHub Desktop.
Save neaf/5684177 to your computer and use it in GitHub Desktop.
Deploy this initializer before migrations involving dropping/changing names of columns
model = MyModel
column_names = %w{ first_column second_column }
columns = model.columns.select { |c| column_names.include?(c.name) }
columns.each do |c|
model.columns.delete(c)
end
@neaf
Copy link
Author

neaf commented May 31, 2013

If you just run migration with drop column statement ActiveRecord in your app instance will continue to issue queries with non-existing items in column list causing exceptions.

To avoid downtime deploy this initialzier before dropping columns.

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