Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 08197200D49 for ; Thu, 19 Oct 2017 10:54:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 06BF21609E2; Thu, 19 Oct 2017 08:54:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1AFD0160BF0 for ; Thu, 19 Oct 2017 10:54:16 +0200 (CEST) Received: (qmail 24899 invoked by uid 500); 19 Oct 2017 08:54:16 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 24668 invoked by uid 99); 19 Oct 2017 08:54:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Oct 2017 08:54:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2BF1FDFD8C; Thu, 19 Oct 2017 08:54:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Thu, 19 Oct 2017 08:54:20 -0000 Message-Id: <23d142c6603b458790a50c37ed657ddd@git.apache.org> In-Reply-To: <637174e9befe44669f1190bbb5d48070@git.apache.org> References: <637174e9befe44669f1190bbb5d48070@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/10] ignite git commit: IGNITE-6647 Web Console: Implemented support of schema migration scripts. archived-at: Thu, 19 Oct 2017 08:54:18 -0000 IGNITE-6647 Web Console: Implemented support of schema migration scripts. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c65399c7 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c65399c7 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c65399c7 Branch: refs/heads/ignite-5937 Commit: c65399c70136ce08d26de3a63204d931d4f96e9e Parents: bab8acb Author: Alexey Kuznetsov Authored: Thu Oct 19 09:43:20 2017 +0700 Committer: Alexey Kuznetsov Committed: Thu Oct 19 09:43:20 2017 +0700 ---------------------------------------------------------------------- modules/web-console/DEVNOTES.txt | 6 +++ modules/web-console/backend/index.js | 53 +++++++++++++++----- .../web-console/backend/migrations/README.txt | 4 ++ modules/web-console/backend/package.json | 1 + 4 files changed, 52 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/c65399c7/modules/web-console/DEVNOTES.txt ---------------------------------------------------------------------- diff --git a/modules/web-console/DEVNOTES.txt b/modules/web-console/DEVNOTES.txt index 85ec958..aa8702e 100644 --- a/modules/web-console/DEVNOTES.txt +++ b/modules/web-console/DEVNOTES.txt @@ -27,3 +27,9 @@ How to run console in development mode: If needed run "npm install --no-optional" (if dependencies changed) and start webpack in development mode "npm run dev". 4. In browser open: http://localhost:9000 + +How to migrate model: + +1. Model will be upgraded on first start. +2. To downgrade model execute in terminal following command: "./node_modules/.bin/migrate down -d ". + Example: "./node_modules/.bin/migrate down add_index -d mongodb://localhost/console". http://git-wip-us.apache.org/repos/asf/ignite/blob/c65399c7/modules/web-console/backend/index.js ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/index.js b/modules/web-console/backend/index.js index f6ba439..06a38f8 100644 --- a/modules/web-console/backend/index.js +++ b/modules/web-console/backend/index.js @@ -17,13 +17,15 @@ 'use strict'; +const _ = require('lodash'); const fs = require('fs'); const path = require('path'); const http = require('http'); const https = require('https'); +const MigrateMongoose = require('migrate-mongoose'); const igniteModules = process.env.IGNITE_MODULES ? - path.join(path.normalize(process.env.IGNITE_MODULES), 'backend') : './ignite_modules'; + path.join(path.normalize(process.env.IGNITE_MODULES), 'backend') : path.join(__dirname, 'ignite_modules'); let injector; @@ -35,7 +37,7 @@ try { injector = require(igniteModulesInjector); } catch (ignore) { - injector = require(path.join(__dirname, './injector')); + injector = require(path.join(__dirname, 'injector')); } /** @@ -63,15 +65,6 @@ const _onError = (addr, error) => { }; /** - * Event listener for HTTP server "listening" event. - */ -const _onListening = (addr) => { - const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; - - console.log('Start listening on ' + bind); -}; - -/** * @param settings * @param {ApiServer} apiSrv * @param {AgentsHandler} agentsHnd @@ -98,7 +91,43 @@ const init = ([settings, apiSrv, agentsHnd, browsersHnd]) => { process.send('running'); }; -Promise.all([injector('settings'), injector('api-server'), injector('agents-handler'), injector('browsers-handler')]) +/** + * Run mongo model migration. + * + * @param dbConnectionUri Mongo connection url. + * @param group Migrations group. + * @param migrationsPath Migrations path. + */ +const migrate = (dbConnectionUri, group, migrationsPath) => { + const migrator = new MigrateMongoose({ + migrationsPath, + dbConnectionUri, + autosync: true + }); + + console.log(`Running ${group} migrations...`); + + return migrator.run('up') + .then(() => console.log(`All ${group} migrations finished successfully.`)) + .catch((err) => { + const msg = _.get(err, 'message'); + + if (_.startsWith(msg, 'There are no migrations to run') || _.startsWith(msg, 'There are no pending migrations.')) { + console.log(`There are no ${group} migrations to run.`); + + return; + } + + throw err; + }); +}; + +injector('settings') + .then(({mongoUrl}) => { + return migrate(mongoUrl, 'Ignite', path.join(__dirname, 'migrations')) + .then(() => migrate(mongoUrl, 'Ignite Modules', path.join(igniteModules, 'migrations'))); + }) + .then(() => Promise.all([injector('settings'), injector('api-server'), injector('agents-handler'), injector('browsers-handler')])) .then(init) .catch((err) => { console.error(err); http://git-wip-us.apache.org/repos/asf/ignite/blob/c65399c7/modules/web-console/backend/migrations/README.txt ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/migrations/README.txt b/modules/web-console/backend/migrations/README.txt new file mode 100644 index 0000000..e907fad --- /dev/null +++ b/modules/web-console/backend/migrations/README.txt @@ -0,0 +1,4 @@ +Ignite Web Console +====================================== + +This folder contains scripts for model migration. http://git-wip-us.apache.org/repos/asf/ignite/blob/c65399c7/modules/web-console/backend/package.json ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/package.json b/modules/web-console/backend/package.json index 07af45f..29aa734 100644 --- a/modules/web-console/backend/package.json +++ b/modules/web-console/backend/package.json @@ -40,6 +40,7 @@ "glob": "7.1.2", "jszip": "3.1.3", "lodash": "4.17.4", + "migrate-mongoose": "3.2.2", "mongoose": "4.11.4", "morgan": "1.8.2", "nconf": "0.8.4",