Properly delete dependent apps and their corresponding devices

This commit is contained in:
Pablo Carranza Velez 2016-10-29 15:10:14 +00:00
parent 3a86d8ec48
commit 9af4ed0397
2 changed files with 6 additions and 3 deletions

View File

@ -1,3 +1,5 @@
* Properly delete dependent apps and their corresponding devices [Pablo]
# v2.8.0
* Add HostConfig in container create instead of start [Pablo]

View File

@ -239,8 +239,7 @@ exports.fetchAndSetTargetsForDependentApps = (state, fetchFn, apiKey) ->
return app.commit? and app.imageId? and !_.some(localApps, imageId: app.imageId)
toBeRemoved = _.filter localApps, (app, appId) ->
return app.commit? and !_.some(remoteApps, imageId: app.imageId)
toBeDeletedFromDB = _.filter localApps, (app, appId) ->
return !remoteApps[appId]?
toBeDeletedFromDB = _(localApps).reject((app, appId) -> remoteApps[appId]?).map('appId').value()
Promise.map toBeDownloaded, (app) ->
fetchFn(app, false)
.then ->
@ -258,7 +257,9 @@ exports.fetchAndSetTargetsForDependentApps = (state, fetchFn, apiKey) ->
knex('dependentApp').insert(app) if n == 0
)
.then ->
knex('dependentApp').del().whereIn('appId', _.keys(toBeDeletedFromDB))
knex('dependentDevice').del().whereIn('appId', toBeDeletedFromDB)
.then ->
knex('dependentApp').del().whereIn('appId', toBeDeletedFromDB)
.then ->
knex('dependentDevice').update({ markedForDeletion: true }).whereNotIn('uuid', _.keys(state.devices))
.then ->