From f6a0754fdacf9b890292f1efc62a9035bceb454a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Sep 2016 23:10:32 +0200 Subject: [PATCH] Server: fix migration at installation --- server/initializers/database.js | 2 +- server/initializers/installer.js | 5 ++++- server/initializers/migrations/0010-users-password.js | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/server/initializers/database.js b/server/initializers/database.js index 1da574631..45c8a240d 100644 --- a/server/initializers/database.js +++ b/server/initializers/database.js @@ -7,9 +7,9 @@ const logger = require('../helpers/logger') // Bootstrap models require('../models/application') +require('../models/oauth-token') require('../models/user') require('../models/oauth-client') -require('../models/oauth-token') require('../models/pods') require('../models/video') // Request model needs Video model diff --git a/server/initializers/installer.js b/server/initializers/installer.js index 974402094..8c3148e79 100644 --- a/server/initializers/installer.js +++ b/server/initializers/installer.js @@ -13,6 +13,7 @@ const constants = require('./constants') const logger = require('../helpers/logger') const peertubeCrypto = require('../helpers/peertube-crypto') +const Application = mongoose.model('Application') const Client = mongoose.model('OAuthClient') const User = mongoose.model('User') @@ -117,7 +118,9 @@ function createOAuthAdminIfNotExist (callback) { logger.info('Username: ' + username) logger.info('User password: ' + password) - return callback(null) + logger.info('Creating Application collection.') + const application = new Application({ mongoSchemaVersion: constants.LAST_MONGO_SCHEMA_VERSION }) + application.save(callback) }) }) } diff --git a/server/initializers/migrations/0010-users-password.js b/server/initializers/migrations/0010-users-password.js index e031fa142..a0616a269 100644 --- a/server/initializers/migrations/0010-users-password.js +++ b/server/initializers/migrations/0010-users-password.js @@ -2,6 +2,7 @@ Convert plain user password to encrypted user password. */ +const eachSeries = require('async/eachSeries') const mongoose = require('mongoose') const User = mongoose.model('User') @@ -10,11 +11,9 @@ exports.up = function (callback) { User.list(function (err, users) { if (err) return callback(err) - users.forEach(function (user) { - user.save() - }) - - return callback(null) + eachSeries(users, function (user, callbackEach) { + user.save(callbackEach) + }, callback) }) } -- 2.25.1