From 00d6b0dda4b1964ab11127851c0fc7106cc0f912 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Sep 2016 22:36:36 +0200 Subject: Add migration (for db, folders...) mechanism --- .../migrations/0005-create-application.js | 17 ++++++++++++++++ .../initializers/migrations/0010-users-password.js | 23 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 server/initializers/migrations/0005-create-application.js create mode 100644 server/initializers/migrations/0010-users-password.js (limited to 'server/initializers/migrations') diff --git a/server/initializers/migrations/0005-create-application.js b/server/initializers/migrations/0005-create-application.js new file mode 100644 index 000000000..e99dec019 --- /dev/null +++ b/server/initializers/migrations/0005-create-application.js @@ -0,0 +1,17 @@ +/* + Create the application collection in MongoDB. + Used to store the actual MongoDB scheme version. +*/ + +const mongoose = require('mongoose') + +const Application = mongoose.model('Application') + +exports.up = function (callback) { + const application = new Application() + application.save(callback) +} + +exports.down = function (callback) { + throw new Error('Not implemented.') +} diff --git a/server/initializers/migrations/0010-users-password.js b/server/initializers/migrations/0010-users-password.js new file mode 100644 index 000000000..e031fa142 --- /dev/null +++ b/server/initializers/migrations/0010-users-password.js @@ -0,0 +1,23 @@ +/* + Convert plain user password to encrypted user password. +*/ + +const mongoose = require('mongoose') + +const User = mongoose.model('User') + +exports.up = function (callback) { + User.list(function (err, users) { + if (err) return callback(err) + + users.forEach(function (user) { + user.save() + }) + + return callback(null) + }) +} + +exports.down = function (callback) { + throw new Error('Not implemented.') +} -- cgit v1.2.3 From f6a0754fdacf9b890292f1efc62a9035bceb454a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Sep 2016 23:10:32 +0200 Subject: Server: fix migration at installation --- server/initializers/migrations/0010-users-password.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'server/initializers/migrations') 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) }) } -- cgit v1.2.3 From c60f2212fd326c323dc2d145ba64080612b655d3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Sep 2016 22:41:38 +0200 Subject: Server: migration script that add admin role to root user --- server/initializers/migrations/0015-admin-role.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 server/initializers/migrations/0015-admin-role.js (limited to 'server/initializers/migrations') diff --git a/server/initializers/migrations/0015-admin-role.js b/server/initializers/migrations/0015-admin-role.js new file mode 100644 index 000000000..af06dca9e --- /dev/null +++ b/server/initializers/migrations/0015-admin-role.js @@ -0,0 +1,16 @@ +/* + Set the admin role to the root user. +*/ + +const constants = require('../constants') +const mongoose = require('mongoose') + +const User = mongoose.model('User') + +exports.up = function (callback) { + User.update({ username: 'root' }, { role: constants.USER_ROLES.ADMIN }, callback) +} + +exports.down = function (callback) { + throw new Error('Not implemented.') +} -- cgit v1.2.3