diff --git a/migrations/20190303024631-apps-default-mailboxName.js b/migrations/20190303024631-apps-default-mailboxName.js new file mode 100644 index 000000000..a63b4570e --- /dev/null +++ b/migrations/20190303024631-apps-default-mailboxName.js @@ -0,0 +1,27 @@ +'use strict'; + +var async = require('async'), + crypto = require('crypto'), + fs = require('fs'), + os = require('os'), + path = require('path'), + safe = require('safetydance'), + tldjs = require('tldjs'); + +exports.up = function(db, callback) { + db.all('SELECT * FROM apps, subdomains WHERE apps.id=subdomains.appId AND type="primary"', function (error, apps) { + if (error) return callback(error); + + async.eachSeries(apps, function (app, iteratorDone) { + if (app.mailboxName) return iteratorDone(); + + const mailboxName = (app.subdomain ? app.subdomain : JSON.parse(app.manifestJson).title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '')) + '.app'; + + db.runSql('UPDATE apps SET mailboxName=? WHERE id=?', [ mailboxName, app.id ], iteratorDone); + }, callback); + }); +}; + +exports.down = function(db, callback) { + callback(); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index da0c2341f..175f73543 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -83,7 +83,7 @@ CREATE TABLE IF NOT EXISTS apps( robotsTxt TEXT, enableBackup BOOLEAN DEFAULT 1, // misnomer: controls automatic daily backups enableAutomaticUpdate BOOLEAN DEFAULT 1, - mailboxName VARCHAR(128), // mailbox of this app + mailboxName VARCHAR(128), // mailbox of this app. default allocated as '.app' // the following fields do not belong here, they can be removed when we use a queue for apptask restoreConfigJson VARCHAR(256), // used to pass backupId to restore from to apptask diff --git a/src/appdb.js b/src/appdb.js index e4e389d84..bbd13d976 100644 --- a/src/appdb.js +++ b/src/appdb.js @@ -265,6 +265,7 @@ function add(id, appStoreId, manifest, location, domain, ownerId, portBindings, assert.strictEqual(typeof ownerId, 'string'); assert.strictEqual(typeof portBindings, 'object'); assert(data && typeof data === 'object'); + assert(typeof data.mailboxName === 'string' && data.mailboxName); // non-empty string assert.strictEqual(typeof callback, 'function'); portBindings = portBindings || { }; @@ -281,7 +282,7 @@ function add(id, appStoreId, manifest, location, domain, ownerId, portBindings, var robotsTxt = 'robotsTxt' in data ? data.robotsTxt : null; var debugModeJson = data.debugMode ? JSON.stringify(data.debugMode) : null; var env = data.env || {}; - const mailboxName = data.mailboxName || null; + const mailboxName = data.mailboxName; var queries = [];