From a522242e7a0c8ba6259076588ed500b9752d61df Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Sat, 21 Feb 2015 18:43:03 +1100 Subject: [PATCH] dealing with invalid live data in migration --- ...dd_address_instances_to_existing_enterprise_groups.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb b/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb index 0800948126..23fc038ce8 100644 --- a/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb +++ b/db/migrate/20150115050936_add_address_instances_to_existing_enterprise_groups.rb @@ -6,7 +6,14 @@ class AddAddressInstancesToExistingEnterpriseGroups < ActiveRecord::Migration next if g.address.present? address = Spree::Address.new(firstname: 'unused', lastname: 'unused', address1: 'undefined', city: 'undefined', zipcode: 'undefined', state: state, country: country, phone: 'undefined') g.address = address - g.save + # some groups are invalid, because of a missing description + g.save!(validate: false) end end + + def self.down + # we can't know which addresses were already there and which weren't + # and we can't remove addresses as long as they are referenced and + # required by the model + end end