Do not delete old if the new one is the same domain

Stephen Paul Weber created

Change summary

lib/registration.rb | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)

Detailed changes

lib/registration.rb 🔗

@@ -667,13 +667,14 @@ class Registration
 			def save_instance_and_wait(domain, launched)
 				instance = ::Snikket::CustomerInstance.for(@customer, domain, launched)
 				repo = ::Snikket::Repo.new(db: @db)
-				repo.del(@old).then { repo.put(instance) }.then do
-					if launched.status == :needs_dns
-						NeedsDNS.new(@customer, instance, @tel, launched.records).write
-					else
-						GetInvite.for(@customer, instance, @tel, db: @db).then(&:write)
+				(@old&.domain == domain ? EMPromise.resolve(nil) : repo.del(@old))
+					.then { repo.put(instance) }.then do
+						if launched.status == :needs_dns
+							NeedsDNS.new(@customer, instance, @tel, launched.records).write
+						else
+							GetInvite.for(@customer, instance, @tel, db: @db).then(&:write)
+						end
 					end
-				end
 			end
 
 			def empty_nil(s)