From c357efe4da311e0537909df4d8bc32c8fd6bf4bb Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Wed, 28 Sep 2016 11:09:50 -0700 Subject: [PATCH] just ignore error if we cannot import mailbox this allows the box code to not crash if the user already has existing conflicting group and user names --- migrations/20160921205726-mailboxes-add-ownerId.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/migrations/20160921205726-mailboxes-add-ownerId.js b/migrations/20160921205726-mailboxes-add-ownerId.js index 427477aad..ee1e46a26 100644 --- a/migrations/20160921205726-mailboxes-add-ownerId.js +++ b/migrations/20160921205726-mailboxes-add-ownerId.js @@ -2,6 +2,11 @@ var dbm = dbm || require('db-migrate'); +function LOG_ERROR(error, next) { + if (error) console.error(error); + next(); +} + exports.up = function(db, callback) { async.series([ db.runSql.bind(db, 'ALTER TABLE mailboxes ADD COLUMN ownerId VARCHAR(128)'), @@ -14,7 +19,7 @@ exports.up = function(db, callback) { if (error) return done(error); async.eachSeries(results, function (g, next) { - db.runSql('INSERT INTO mailboxes (ownerId, ownerType, name) VALUES (?, ?, ?)', [ g.id, 'group', g.name ], next); + db.runSql('INSERT INTO mailboxes (ownerId, ownerType, name) VALUES (?, ?, ?)', [ g.id, 'group', g.name ], LOG_ERROR); }, done); }); }, @@ -29,7 +34,7 @@ exports.up = function(db, callback) { if (!manifest.addons['sendmail'] && !manifest.addons['recvmail']) return next(); var mailboxName = (a.location ? a.location : manifest.title.replace(/[^a-zA-Z0-9]/g, '')) + '.app'; - db.runSql('INSERT INTO mailboxes (ownerId, ownerType, name) VALUES (?, ?, ?)', [ a.id, 'app', mailboxName ], next); + db.runSql('INSERT INTO mailboxes (ownerId, ownerType, name) VALUES (?, ?, ?)', [ a.id, 'app', mailboxName ], LOG_ERROR); }, done); }); }, @@ -42,7 +47,7 @@ exports.up = function(db, callback) { async.eachSeries(results, function (u, next) { if (!u.username) return next(); - db.runSql('UPDATE mailboxes SET ownerId = ?, ownerType = ? WHERE name = ? OR targetAlias = ?', [ u.id, 'user', u.username, u.username ], done); + db.runSql('UPDATE mailboxes SET ownerId = ?, ownerType = ? WHERE name = ? OR targetAlias = ?', [ u.id, 'user', u.username, u.username ], LOG_ERROR); }, done); }); },