Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handling for knex-migrator being executed in Ghost 2.0 #765

Merged
merged 3 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Skipped running db migration on ghost install
refs #759

- same as for `ghost update`
- do not run db migrations on `ghost install`
  • Loading branch information
kirrg001 committed Jul 27, 2018
commit 38f3489118d594a25df2632323d431ead86b3a1f
13 changes: 12 additions & 1 deletion lib/commands/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SetupCommand extends Command {
const os = require('os');
const url = require('url');
const path = require('path');
const semver = require('semver');

const linux = require('../tasks/linux');
const migrate = require('../tasks/migrate');
Expand Down Expand Up @@ -171,10 +172,20 @@ class SetupCommand extends Command {
}));

if (argv.migrate !== false) {
const instance = this.system.getInstance();

// Tack on db migration task to the end
tasks.push({
title: 'Running database migrations',
task: migrate
task: 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')) {
return false;
}

return true;
}
});
}

Expand Down
78 changes: 73 additions & 5 deletions test/unit/commands/setup-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,70 @@ describe('Unit: Commands > Setup', function () {
});
});

it('Initial stage is setup properly, but skips db migrations', function () {
const migrateStub = sinon.stub().resolves();
const SetupCommand = proxyquire(modulePath, {
'../tasks/migrate': migrateStub
});

const listr = sinon.stub();
const aIstub = sinon.stub();
const config = configStub();
const cliConfigStub = configStub();

cliConfigStub.get.withArgs('active-version').returns('2.0.0');

config.get.withArgs('url').returns('https://ghost.org');
config.has.returns(false);

const system = {
getInstance: () => {
return {
checkEnvironment: () => true,
apples: true,
config,
dir: '/var/www/ghost',
cliConfig: cliConfigStub
};
},
addInstance: aIstub,
hook: () => Promise.resolve()
};
const ui = {
run: () => Promise.resolve(),
listr: listr,
confirm: () => Promise.resolve(false)
};
const argv = {
prompt: true,
'setup-linux-user': false
};

ui.listr.callsFake((tasks, ctx) => {
return Promise.each(tasks, (task) => {
if ((task.skip && task.skip(ctx)) || (task.enabled && !task.enabled(ctx))) {
return;
}

return task.task(ctx);
});
});

const setup = new SetupCommand(ui, system);
return setup.run(argv).then(() => {
expect(listr.calledOnce).to.be.true;
expect(migrateStub.called).to.be.false;
});
});

it('Initial stage is setup properly', function () {
const listr = sinon.stub().resolves();
const aIstub = sinon.stub();
const config = configStub();
const cliConfigStub = configStub();

cliConfigStub.get.withArgs('active-version').returns('1.25.0');

config.get.withArgs('url').returns('https://ghost.org');
config.has.returns(false);

Expand All @@ -234,7 +294,8 @@ describe('Unit: Commands > Setup', function () {
checkEnvironment: () => true,
apples: true,
config,
dir: '/var/www/ghost'
dir: '/var/www/ghost',
cliConfig: cliConfigStub
};
},
addInstance: aIstub,
Expand All @@ -258,7 +319,7 @@ describe('Unit: Commands > Setup', function () {
expect(tasks[0].title).to.equal('Setting up instance');
tasks.forEach(function (task) {
expect(task.title).to.not.match(/database migrations/);
})
});

const ctx = {};
tasks[0].task(ctx);
Expand Down Expand Up @@ -348,7 +409,8 @@ describe('Unit: Commands > Setup', function () {
log: stubs.log
};
system = {
hook: () => Promise.resolve()
hook: () => Promise.resolve(),
getInstance: sinon.stub()
};
});

Expand Down Expand Up @@ -451,7 +513,10 @@ describe('Unit: Commands > Setup', function () {
listr: sinon.stub().resolves()
};
const skipStub = sinon.stub();
const system = {hook: () => Promise.resolve()};
const system = {
hook: () => Promise.resolve(),
getInstance: sinon.stub()
};
const setup = new SetupCommand(ui, system);
setup.runCommand = () => Promise.resolve();
setup.addStage('zest', () => true, null, 'Zesty');
Expand All @@ -477,7 +542,10 @@ describe('Unit: Commands > Setup', function () {
confirm: sinon.stub().callsFake(confirm)
};
const skipStub = sinon.stub();
const system = {hook: () => Promise.resolve()};
const system = {
hook: () => Promise.resolve(),
getInstance: sinon.stub()
};
const setup = new SetupCommand(ui, system);
let tasks;
const runCommand = sinon.stub(setup, 'runCommand').resolves();
Expand Down