Skip to content

Commit

Permalink
IGNITE-6647 Web Console: Support recreate index in migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
akuznetsov-os committed Dec 29, 2017
1 parent b206085 commit a1b1f6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/web-console/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ const init = ([settings, apiSrv, agentsHnd, browsersHnd]) => {
* @param dbConnectionUri Mongo connection url.
* @param group Migrations group.
* @param migrationsPath Migrations path.
* @param collectionName Name of collection where migrations write info about applied scripts.
*/
const migrate = (dbConnectionUri, group, migrationsPath) => {
const migrate = (dbConnectionUri, group, migrationsPath, collectionName) => {
const migrator = new MigrateMongoose({
migrationsPath,
dbConnectionUri,
collectionName,
autosync: true
});

Expand Down Expand Up @@ -144,7 +146,7 @@ injector.log.debug = () => {};
Promise.all([injector('settings'), injector('mongo')])
.then(([{mongoUrl}]) => {
return migrate(mongoUrl, 'Ignite', path.join(__dirname, 'migrations'))
.then(() => migrate(mongoUrl, 'Ignite Modules', path.join(igniteModules, 'migrations')));
.then(() => migrate(mongoUrl, 'Ignite Modules', path.join(igniteModules, 'migrations'), 'migrationsModules'));
})
.then(() => Promise.all([injector('settings'), injector('api-server'), injector('agents-handler'), injector('browsers-handler')]))
.then(init)
Expand Down
30 changes: 30 additions & 0 deletions modules/web-console/backend/migrations/recreate-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

module.exports = function(done, model, oldIdxName, oldIdx, newIdx) {
model.indexExists(oldIdxName)
.then((exists) => {
if (exists) {
return model.dropIndex(oldIdx)
.then(() => model.createIndex(newIdx, {unique: true}));
}
})
.then(() => done())
.catch(done);
};

0 comments on commit a1b1f6c

Please sign in to comment.