Skip to content

Instantly share code, notes, and snippets.

@dwradcliffe
Created February 9, 2011 15:40
Show Gist options
  • Save dwradcliffe/818668 to your computer and use it in GitHub Desktop.
Save dwradcliffe/818668 to your computer and use it in GitHub Desktop.
spree migration fix
class GenerateAnonymousUsers < ActiveRecord::Migration
def self.up
User.reset_column_information
puts Order.where(:user_id => nil).where(:state != "balance_due").count.to_s + " remaining..."
Order.where(:user_id => nil).where(:state != "balance_due").each do |order|
user = User.anonymous!
user.email ||= order.email
puts user.login
user.save!
order.update_attribute_without_callbacks("user_id", user.id)
end
end
def self.down
end
end
class RemoveShippedState < ActiveRecord::Migration
def self.up
Order.where(:state => 'shipped').each do |order|
order.update_attribute_without_callbacks("state", "complete")
order.shipments.each do |shipment|
shipment.update_attribute_without_callbacks("state", "shipped")
end
end
end
def self.down
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment