diff --git a/lib/commands/start.js b/lib/commands/start.js index 88ec768ee..d8546e98b 100644 --- a/lib/commands/start.js +++ b/lib/commands/start.js @@ -45,6 +45,30 @@ 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! + * + * 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)), 'Starting Ghost instance' diff --git a/package.json b/package.json index 79aebbacf..c7efb4506 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.6", "npm": "2.15.11", "semver": "5.3.0", "symlink-or-copy": "1.1.6",