diff --git a/lib/commands/setup.js b/lib/commands/setup.js index bda6b1919..e14e66e4c 100644 --- a/lib/commands/setup.js +++ b/lib/commands/setup.js @@ -180,7 +180,7 @@ class SetupCommand extends Command { task: migrator.migrate, // CASE: We are about to install Ghost 2.0. We moved the execution of knex-migrator into Ghost. enabled: () => { - if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0')) { + if (semver.major(instance.cliConfig.get('active-version')) === 2) { return false; } diff --git a/lib/commands/update.js b/lib/commands/update.js index c1a8f1ff2..550d8ae9f 100644 --- a/lib/commands/update.js +++ b/lib/commands/update.js @@ -72,8 +72,8 @@ class UpdateCommand extends Command { task: majorUpdate, // CASE: Skip if you are already on ^2 or you update from v1 to v1. enabled: () => { - if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0') || - !semver.satisfies(context.version, '^2.0.0')) { + if (semver.major(instance.cliConfig.get('active-version')) === 2 || + semver.major(context.version) === 1) { return false; } @@ -96,9 +96,10 @@ class UpdateCommand extends Command { task: migrator.migrate, // CASE: We have moved the execution of knex-migrator into Ghost 2.0.0. // If you are already on v2 or you update from v1 to v2, then skip the task. + // We compare the major versions, otherwise pre-releases won't match. enabled: () => { - if (semver.satisfies(instance.cliConfig.get('active-version'), '^2.0.0') || - semver.satisfies(context.version, '^2.0.0')) { + if (semver.major(instance.cliConfig.get('active-version')) === 2 || + semver.major(context.version) === 2) { return false; } diff --git a/lib/process-manager.js b/lib/process-manager.js index 117d5b032..bd1fbcb22 100644 --- a/lib/process-manager.js +++ b/lib/process-manager.js @@ -76,7 +76,7 @@ class ProcessManager { stopOnError: true, port: this.instance.config.get('server.port'), host: this.instance.config.get('server.host', 'localhost'), - useNetServer: semver.satisfies(this.instance.cliConfig.get('active-version'), '^2.0.0') + useNetServer: semver.major(this.instance.cliConfig.get('active-version')) === 2 }, options || {}); return portPolling(options).catch((err) => { diff --git a/lib/tasks/migrator.js b/lib/tasks/migrator.js index 92a1f4588..dec06aad5 100644 --- a/lib/tasks/migrator.js +++ b/lib/tasks/migrator.js @@ -85,7 +85,7 @@ module.exports.rollback = function runRollback(context) { // Ghost 2.0.0 uses the new knex-migrator version. We have to ensure you can still use CLI 1.9 with an older blog, because // we haven't restricted a CLI version range in Ghost (we only used cli: > X.X.X) - if (semver.satisfies(context.instance.cliConfig.get('active-version'), '^2.0.0')) { + if (semver.major(context.instance.cliConfig.get('active-version')) === 2) { args = ['--force', '--v', context.instance.cliConfig.get('previous-version'), '--mgpath', currentDir]; } else { args = ['--force', '--mgpath', currentDir]; diff --git a/test/unit/tasks/migrator-spec.js b/test/unit/tasks/migrator-spec.js index 1ef70d216..0825c6045 100644 --- a/test/unit/tasks/migrator-spec.js +++ b/test/unit/tasks/migrator-spec.js @@ -158,9 +158,15 @@ describe('Unit: Tasks > Migrator', function () { }); describe('rollback', function () { + let cliConfig; + + beforeEach(function () { + cliConfig = configStub(); + cliConfig.get.withArgs('active-version').returns('1.25.3'); + }); + it('runs direct command if useGhostUser returns false', function () { const config = configStub(); - const cliConfig = configStub(); const execaStub = sinon.stub().resolves(); const useGhostUserStub = sinon.stub().returns(false); @@ -181,7 +187,7 @@ describe('Unit: Tasks > Migrator', function () { }); }); - it('forward version option to knex-migrator if blog is on v1', function () { + it('forward version option to knex-migrator if blog jumps from v1 to v2', function () { const config = configStub(); const cliConfig = configStub(); const execaStub = sinon.stub().resolves(); @@ -209,7 +215,6 @@ describe('Unit: Tasks > Migrator', function () { it('runs sudo command if useGhostUser returns true', function () { const config = configStub(); - const cliConfig = configStub(); const execaStub = sinon.stub().resolves(); const useGhostUserStub = sinon.stub().returns(true); @@ -230,7 +235,6 @@ describe('Unit: Tasks > Migrator', function () { it('throws config error with db host if database not found', function () { const config = configStub(); - const cliConfig = configStub(); const execaStub = sinon.stub().returns(Promise.reject({stderr: 'CODE: ENOTFOUND'})); const useGhostUserStub = sinon.stub().returns(false); @@ -249,7 +253,6 @@ describe('Unit: Tasks > Migrator', function () { it('throws config error with db user if access denied error', function () { const config = configStub(); - const cliConfig = configStub(); const execaStub = sinon.stub().returns(Promise.reject({stderr: 'CODE: ER_ACCESS_DENIED_ERROR'})); const useGhostUserStub = sinon.stub().returns(false); @@ -268,7 +271,6 @@ describe('Unit: Tasks > Migrator', function () { it('throws system error if sqlite3 error is thrown by knex', function () { const config = configStub(); - const cliConfig = configStub(); const execaStub = sinon.stub().returns(Promise.reject({stdout: 'Knex: run\n$ npm install sqlite3 --save\nError:'})); const useGhostUserStub = sinon.stub().returns(false); @@ -287,7 +289,6 @@ describe('Unit: Tasks > Migrator', function () { it('knex-migrator complains that no more migrations to rollback available', function () { const config = configStub(); - const cliConfig = configStub(); const execaStub = sinon.stub().returns(Promise.reject({stderr: 'No migrations available to rollback'})); const useGhostUserStub = sinon.stub().returns(false); @@ -305,7 +306,6 @@ describe('Unit: Tasks > Migrator', function () { process.argv = ['node', 'ghost', 'update', '--rollback']; const config = configStub(); - const cliConfig = configStub(); const execaStub = sinon.stub().rejects({stderr: 'YA_GOOFED'}); const useGhostUserStub = sinon.stub().returns(false);