diff --git a/lib/registration.rb b/lib/registration.rb index 358ac2d9800465ba671b9b7d2d26c681e2f40657..27759bfa45872314beed3f9e24aac2686ed824e9 100644 --- a/lib/registration.rb +++ b/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)