diff --git a/src/appdb.js b/src/appdb.js index 03f157a55..b1fe63600 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -27,6 +27,8 @@ exports = module.exports = { setOwner: setOwner, transferOwnership: transferOwnership, + setSubdomainDnsRecordId: setSubdomainDnsRecordId, + // installation codes (keep in sync in UI) ISTATE_PENDING_INSTALL: 'pending_install', // installs and fresh reinstalls ISTATE_PENDING_CLONE: 'pending_clone', // clone @@ -623,3 +625,17 @@ function transferOwnership(oldOwnerId, newOwnerId, callback) { callback(null); }); } + +function setSubdomainDnsRecordId(domain, subdomain, dnsRecordId, callback) { + assert.strictEqual(typeof domain, 'string'); + assert.strictEqual(typeof subdomain, 'string'); + assert.strictEqual(typeof dnsRecordId, 'string'); + assert.strictEqual(typeof callback, 'function'); + + database.query('UPDATE subdomains SET dnsRecordId = ? WHERE domain = ? AND subdomain = ?', [ dnsRecordId, domain, subdomain ], function (error, results) { + if (error && error.code === 'ER_NO_REFERENCED_ROW_2') return callback(new DatabaseError(DatabaseError.NOT_FOUND, 'No such subdomain')); + if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); + + callback(null); + }); +} diff --git a/src/apptask.js b/src/apptask.js index 8b86c4242..4429b5938 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -343,10 +343,8 @@ function registerAlternateDomains(app, overwrite, callback) { }, function (error, result) { if (error || result instanceof Error) return callback(error || result); - // TODO we need to stash this into the subdomains table instead of apps table // dnsRecordId tracks whether we created this DNS record so that we can unregister later - // updateApp(app, { dnsRecordId: result }, callback); - callback(); + appdb.setSubdomainDnsRecordId(domain.domain, domain.subdomain, result, callback); }); }, callback); });