diff --git a/lib/authorization/storage.js b/lib/authorization/storage.js index 054f9a07b0d..614f8c78051 100644 --- a/lib/authorization/storage.js +++ b/lib/authorization/storage.js @@ -122,6 +122,11 @@ function init (env, ctx) { , { name: 'activity', permissions: [ 'api:activity:create' ] } ]; + storage.ensureIndexes = function ensureIndexes() { + ctx.store.ensureIndexes(rolesCollection, ['name']); + ctx.store.ensureIndexes(subjectsCollection, ['name']); + } + storage.getSHA1 = function getSHA1 (message) { var shasum = crypto.createHash('sha1'); shasum.update(message); diff --git a/lib/server/bootevent.js b/lib/server/bootevent.js index edcd35c11cd..60b02b541c8 100644 --- a/lib/server/bootevent.js +++ b/lib/server/bootevent.js @@ -185,6 +185,7 @@ function boot (env, language) { } ctx.authorization = require('../authorization')(env, ctx); + ctx.authorization.storage.ensureIndexes(); ctx.authorization.storage.reload(function loaded (err) { if (err) { ctx.bootErrors = ctx.bootErrors || [ ];