Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create data migration for spree_orders.shipment_total #4684

Closed
BMorearty opened this issue May 13, 2014 · 4 comments
Closed

Create data migration for spree_orders.shipment_total #4684

BMorearty opened this issue May 13, 2014 · 4 comments
Assignees

Comments

@BMorearty
Copy link
Contributor

When the shipment_total column was added to spree_orders, the column was not populated in existing orders (if upgrading from an older version of Spree).

Could someone who's more familiar with the code than I am, please create a migration? Or I'll do it if you point me the right way.

Here's one way that might work:

Spree::Order.find_each { |order| OrderUpdater.new(order).update_shipment_total; order.save }

But it was suggested in IRC that a single SQL "UPDATE" statement might be possible as well, and would certainly be faster.

@huoxito
Copy link
Member

huoxito commented May 30, 2014

played a while with sql today, I think something like this might fix the issue is a faster way:

UPDATE spree_orders
SET shipment_total = (SELECT SUM(spree_shipments.cost) AS sum_id
                      FROM spree_shipments
                      WHERE spree_shipments.order_id = spree_orders.id)

I'm just not sure right now if we should add a new migration or update existing ones to add that code. At this point perhaps the ideal fix would be add that sample at some upgrade guide.

@peterberkenbosch
Copy link
Member

This is also an issue for tax adjustments btw.

@BMorearty
Copy link
Contributor Author

I would not update the existing migration. I think it's better to add a new one.

However, because the migration is being added late, don't update shipment_total on records that already have a shipment_total. (Orders that were created in Spree 2.2). Add this to the end:

WHERE shipment_total = 0

@huoxito huoxito closed this as completed in a63afca Jun 1, 2014
huoxito added a commit that referenced this issue Jun 1, 2014
Previous to Spree 2.2 orders didn't have a shipment_total. This should
populate that new column for legacy orders

Fixes #4684
@huoxito
Copy link
Member

huoxito commented Jun 1, 2014

Added migration to populate that field on 2-2-stable. Still feels weird to have it there but I hope users read the migrations content before they run it in production. thanks @BMorearty

cpatil pushed a commit to godaddy/spree that referenced this issue Jun 5, 2014
Previous to Spree 2.2 orders didn't have a shipment_total. This should
populate that new column for legacy orders

Fixes spree#4684
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants