From d91c7de02306a3e6ed5826a6129e31dfef029c4b Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Fri, 14 Oct 2016 00:27:44 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20=20use=20knex-migrator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - check database health before starting Ghost - run knex-migrator init if database was never initialised --- lib/commands/start.js | 28 ++++++++++++++++++++++++++-- package.json | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/commands/start.js b/lib/commands/start.js index 88ec768ee..0eefcffe3 100644 --- a/lib/commands/start.js +++ b/lib/commands/start.js @@ -1,4 +1,5 @@ -var BaseCommand = require('./base'); +var KnexMigrator = require('knex-migrator'), + BaseCommand = require('./base'); module.exports = BaseCommand.extend({ name: 'start', @@ -28,7 +29,7 @@ module.exports = BaseCommand.extend({ Promise = require('bluebird'), path = require('path'), self = this, - environment, config, pm, cliConfig; + environment, config, pm, cliConfig, knexMigrator; options = options || {}; environment = (options.production || !options.development) ? 'production' : 'development'; @@ -44,6 +45,29 @@ module.exports = BaseCommand.extend({ // TODO: rethink this return this.runCommand('config', 'paths.contentPath', path.join(process.cwd(), 'content'), {environment: environment}) + .then(function () { + /** + * If we require any JS file from Ghost source code (for example the config), then it's always env-less! + * + * 1. Ghost-CLI requires knex-migrator + * 2. knex-migrator loads the .knex-migrator config file from the current Ghost version + * 3. this is env-less + * + * Alternative solution is: passing the env into knex-migrator, but that feels not right? + * @TODO: rethink + */ + process.env.NODE_ENV = environment; + + // @TODO: where to get this path from? + knexMigrator = new KnexMigrator({ + knexMigratorFilePath: process.cwd() + '/current' + }); + + return knexMigrator.isDatabaseOK() + .catch(function () { + return knexMigrator.init(); + }); + }) .then(function () { return self.ui.run( Promise.resolve(pm.start(process.cwd(), environment)), diff --git a/package.json b/package.json index 79aebbacf..8d1b6e568 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "inquirer": "1.2.2", "lodash": "4.16.4", "log-symbols": "1.0.2", + "knex-migrator": "0.0.3", "npm": "2.15.11", "semver": "5.3.0", "symlink-or-copy": "1.1.6", From 4a146b4afcd7cd53122716ca450279b0a7ed6210 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Mon, 17 Oct 2016 20:28:54 +0200 Subject: [PATCH 2/4] knex-migrator 0.0.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d1b6e568..36b2100f2 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "inquirer": "1.2.2", "lodash": "4.16.4", "log-symbols": "1.0.2", - "knex-migrator": "0.0.3", + "knex-migrator": "0.0.5", "npm": "2.15.11", "semver": "5.3.0", "symlink-or-copy": "1.1.6", From 144f256defe1e93e0ce2aafc85c722fba1dff3b8 Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Mon, 17 Oct 2016 19:12:55 -0500 Subject: [PATCH 3/4] defer loading of knex-migrator until it's needed --- lib/commands/start.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/commands/start.js b/lib/commands/start.js index 0eefcffe3..d8546e98b 100644 --- a/lib/commands/start.js +++ b/lib/commands/start.js @@ -1,5 +1,4 @@ -var KnexMigrator = require('knex-migrator'), - BaseCommand = require('./base'); +var BaseCommand = require('./base'); module.exports = BaseCommand.extend({ name: 'start', @@ -29,7 +28,7 @@ module.exports = BaseCommand.extend({ Promise = require('bluebird'), path = require('path'), self = this, - environment, config, pm, cliConfig, knexMigrator; + environment, config, pm, cliConfig; options = options || {}; environment = (options.production || !options.development) ? 'production' : 'development'; @@ -46,6 +45,8 @@ module.exports = BaseCommand.extend({ // TODO: rethink this return this.runCommand('config', 'paths.contentPath', path.join(process.cwd(), 'content'), {environment: environment}) .then(function () { + var KnexMigrator = require('knex-migrator'), + knexMigrator; /** * If we require any JS file from Ghost source code (for example the config), then it's always env-less! * @@ -67,8 +68,7 @@ module.exports = BaseCommand.extend({ .catch(function () { return knexMigrator.init(); }); - }) - .then(function () { + }).then(function () { return self.ui.run( Promise.resolve(pm.start(process.cwd(), environment)), 'Starting Ghost instance' From 7feba78f226815ed6db114860acfff500f57fa90 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Tue, 18 Oct 2016 10:40:32 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8E=A8=20=20knex-migrator=200.0.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36b2100f2..c7efb4506 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "inquirer": "1.2.2", "lodash": "4.16.4", "log-symbols": "1.0.2", - "knex-migrator": "0.0.5", + "knex-migrator": "0.0.6", "npm": "2.15.11", "semver": "5.3.0", "symlink-or-copy": "1.1.6",