diff --git a/src/appdb.js b/src/appdb.js index 1981993d3..831746e7b 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -423,14 +423,14 @@ function updateWithConstraints(id, app, constraints, callback) { } if ('location' in app && 'domain' in app) { // must be updated together as they are unique together - queries.push({ query: 'UPDATE subdomains SET subdomain = ?, domain = ? WHERE appId = ? AND type = ?', args: [ app.location, app.domain, id, exports.SUBDOMAIN_TYPE_PRIMARY ]}); - } + queries.push({ query: 'DELETE FROM subdomains WHERE appId = ?', args: [ id ]}); // all locations of an app must be updated together + queries.push({ query: 'INSERT INTO subdomains (appId, domain, subdomain, type) VALUES (?, ?, ?, ?)', args: [ id, app.domain, app.location, exports.SUBDOMAIN_TYPE_PRIMARY ]}); - if ('alternateDomains' in app) { - queries.push({ query: 'DELETE FROM subdomains WHERE appId = ? AND type = ?', args: [ id, exports.SUBDOMAIN_TYPE_REDIRECT ]}); - app.alternateDomains.forEach(function (d) { - queries.push({ query: 'INSERT INTO subdomains (appId, domain, subdomain, type) VALUES (?, ?, ?, ?)', args: [ id, d.domain, d.subdomain, exports.SUBDOMAIN_TYPE_REDIRECT ]}); - }); + if ('alternateDomains' in app) { + app.alternateDomains.forEach(function (d) { + queries.push({ query: 'INSERT INTO subdomains (appId, domain, subdomain, type) VALUES (?, ?, ?, ?)', args: [ id, d.domain, d.subdomain, exports.SUBDOMAIN_TYPE_REDIRECT ]}); + }); + } } var fields = [ ], values = [ ];