From f914a6d8698fb4b91a90eb04179bd591e3ce3755 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 13 Mar 2019 14:24:12 +0000 Subject: [PATCH] Add migration to set default stock location on all shipments without stock location This is a modified version of this spree migration: https://github.com/spree/spree/commit/219e09b --- ...90313142051_set_default_stock_location_on_shipments.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/migrate/20190313142051_set_default_stock_location_on_shipments.rb diff --git a/db/migrate/20190313142051_set_default_stock_location_on_shipments.rb b/db/migrate/20190313142051_set_default_stock_location_on_shipments.rb new file mode 100644 index 0000000000..45add57fe3 --- /dev/null +++ b/db/migrate/20190313142051_set_default_stock_location_on_shipments.rb @@ -0,0 +1,8 @@ +class SetDefaultStockLocationOnShipments < ActiveRecord::Migration + def up + if Spree::Shipment.where('stock_location_id IS NULL').count > 0 + location = DefaultStockLocation.find_or_create + Spree::Shipment.where('stock_location_id IS NULL').update_all(stock_location_id: location.id) + end + end +end