Created
February 9, 2011 15:40
-
-
Save dwradcliffe/818668 to your computer and use it in GitHub Desktop.
spree migration fix
This file contains 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 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 |
This file contains 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 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