From da9e756d9f5814e787b060fbeaa39c6abddd439c Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 19 Sep 2013 11:32:00 +1000 Subject: [PATCH] Fix migration for envs without distributors --- ...919010513_ensure_shipping_methods_have_distributors.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/db/migrate/20130919010513_ensure_shipping_methods_have_distributors.rb b/db/migrate/20130919010513_ensure_shipping_methods_have_distributors.rb index 7e7167b00c..271fd5f9df 100644 --- a/db/migrate/20130919010513_ensure_shipping_methods_have_distributors.rb +++ b/db/migrate/20130919010513_ensure_shipping_methods_have_distributors.rb @@ -2,9 +2,13 @@ class EnsureShippingMethodsHaveDistributors < ActiveRecord::Migration def up d = Enterprise.is_distributor.first sms = Spree::ShippingMethod.where('distributor_id IS NULL') - say "Assigning an arbitrary distributor (#{d.name}) to all shipping methods without one (#{sms.count} total)" - sms.update_all(distributor_id: d) + if d + say "Assigning an arbitrary distributor (#{d.name}) to all shipping methods without one (#{sms.count} total)" + sms.update_all(distributor_id: d) + else + say "There are #{sms.count} shipping methods without distributors, but there are no distributors to assign to them" + end end def down