From 1772d34e947ec5e940cc99f53ff0a102e048d69c Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 11 May 2017 10:10:50 +0200 Subject: fix migrator --- app/scripts/lib/migrator/index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index c40c347b5..caa0ef318 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -13,10 +13,10 @@ class Migrator { // run all pending migrations on meta in place migrateData (versionedData = this.generateInitialState()) { const remaining = this.migrations.filter(migrationIsPending) - + if (remaining.length === 0) return versionedData return ( asyncQ.eachSeries(remaining, (migration) => this.runMigration(versionedData, migration)) - .then(() => versionedData) + .then((migratedData) => migratedData.pop()) ) // migration is "pending" if hit has a higher @@ -27,14 +27,13 @@ class Migrator { } runMigration (versionedData, migration) { - return ( - migration.migrate(versionedData) - .then((versionedData) => { - if (!versionedData.data) return Promise.reject(new Error('Migrator - Migration returned empty data')) - if (migration.version !== undefined && versionedData.meta.version !== migration.version) return Promise.reject(new Error('Migrator - Migration did not update version number correctly')) - return Promise.resolve(versionedData) + return migration.migrate(versionedData) + .then((migratedData) => { + if (!migratedData.data) return Promise.reject(new Error('Migrator - Migration returned empty data')) + if (migration.version !== undefined && migratedData.meta.version !== migration.version) return Promise.reject(new Error('Migrator - Migration did not update version number correctly')) + + return Promise.resolve(migratedData) }) - ) } generateInitialState (initState) { -- cgit v1.2.3