From 2341cb927435e36fbc69ef4f070f38a69669d069 Mon Sep 17 00:00:00 2001 From: Tyler Kellen Date: Mon, 24 Aug 2015 00:11:09 -0400 Subject: [PATCH 1/2] all applied migrations on initial migration are new on the initial run, there are no previous entries. this pr sets newEntries to match all applied entries in this case, which fixes gh-2 --- lib/command/apply.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command/apply.ts b/lib/command/apply.ts index 3774a55..1b25e10 100644 --- a/lib/command/apply.ts +++ b/lib/command/apply.ts @@ -54,7 +54,7 @@ export default function apply(config: Config) { let previousEntry = journal.then(es => R.last(es)); let newEntries = Promise.join(previousEntry, apply, (prev, es) => - R.filter(e => e.timestamp > prev.timestamp, es) + prev ? R.filter(e => e.timestamp > prev.timestamp, es) : apply ); return newEntries From db069f6384200b3084742dc9f6fe8ef09c016a29 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 21 Sep 2015 14:56:50 -0400 Subject: [PATCH 2/2] Test apply command with empty journal --- test/command/apply.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/command/apply.ts b/test/command/apply.ts index f52d32b..49758cd 100644 --- a/test/command/apply.ts +++ b/test/command/apply.ts @@ -284,4 +284,31 @@ describe('Command apply', () => { assert.equal(formatSpy.callCount, 1) ); }); + + describe('with empty journal', () => { + before(resetSpies); + + before(() => { + readJournalStub.restore(); + readJournalStub = sinon.stub(runner, 'readJournal', () => + Promise.resolve([]) + ); + + applyAllStub.restore(); + applyAllStub = sinon.stub( + runner, + 'applyAll', + (n: string, c: Config, j: string, ms: files.Migration[]) => + Promise.resolve(R.map(migrationToEntry, ms)) + ); + }); + + it('succeeds', () => + apply(loadObject({commands: {apply: {pending: true}}})) + ); + + it('calls formatJournalEntry for new entries', () => + assert.equal(formatSpy.callCount, 3) + ); + }); });