From d6ee60100dc3dc9882f45c7020bd5dd7415ed460 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 30 Oct 2018 10:05:37 -0700 Subject: [PATCH] fix: When setting target state, delete old apps from the same source In commit 19cd310da367c66cbffdea03245bd987223abc37 this line was deleted, probably to avoid deleting local mode apps when setting the API target and viceversa but we need to delete old apps to avoid problems when moving the device between apps. We now filter by source to avoid the problem with local mode too. Change-type: patch Signed-off-by: Pablo Carranza Velez --- src/application-manager.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/application-manager.coffee b/src/application-manager.coffee index a399bbc9..9ae71921 100644 --- a/src/application-manager.coffee +++ b/src/application-manager.coffee @@ -742,6 +742,8 @@ module.exports = class ApplicationManager extends EventEmitter .tap (appsForDB) => Promise.map appsForDB, (app) => @db.upsertModel('app', app, { appId: app.appId }, trx) + .then (appsForDB) -> + trx('app').where({ source }).whereNotIn('appId', _.map(appsForDB, 'appId')).del() .then => @proxyvisor.setTargetInTransaction(dependent, trx)