Merge pull request #782 from balena-io/fix-delete-old-apps

fix: When setting target state, delete old apps from the same source
This commit is contained in:
Pablo Carranza Vélez 2018-10-31 13:08:48 -07:00 committed by GitHub
commit 0d7335bdee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -742,6 +742,8 @@ module.exports = class ApplicationManager extends EventEmitter
.tap (appsForDB) => .tap (appsForDB) =>
Promise.map appsForDB, (app) => Promise.map appsForDB, (app) =>
@db.upsertModel('app', app, { appId: app.appId }, trx) @db.upsertModel('app', app, { appId: app.appId }, trx)
.then (appsForDB) ->
trx('app').where({ source }).whereNotIn('appId', _.map(appsForDB, 'appId')).del()
.then => .then =>
@proxyvisor.setTargetInTransaction(dependent, trx) @proxyvisor.setTargetInTransaction(dependent, trx)