Server: migration script that add admin role to root user
authorChocobozzz <florian.bigard@gmail.com>
Tue, 27 Sep 2016 20:41:38 +0000 (22:41 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Tue, 27 Sep 2016 20:41:38 +0000 (22:41 +0200)
server/initializers/constants.js
server/initializers/migrations/0015-admin-role.js [new file with mode: 0644]

index 10ae48e9521940118b52c5dc28d30299becfa24b..02043bd45bb5fad6127429c881cd84441276fe5e 100644 (file)
@@ -62,9 +62,13 @@ const MONGO_MIGRATION_SCRIPTS = [
   {
     script: '0010-users-password',
     version: 10
+  },
+  {
+    script: '0015-admin-role',
+    version: 15
   }
 ]
-const LAST_MONGO_SCHEMA_VERSION = 10
+const LAST_MONGO_SCHEMA_VERSION = 15
 
 // Time to wait between requests to the friends (10 min)
 let REQUESTS_INTERVAL = 600000
diff --git a/server/initializers/migrations/0015-admin-role.js b/server/initializers/migrations/0015-admin-role.js
new file mode 100644 (file)
index 0000000..af06dca
--- /dev/null
@@ -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.')
+}