From 6c01b26845cfb8e113d3016ebd595a9098623f62 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 11 May 2017 10:46:17 +0200 Subject: [PATCH] use asyncQ.waterfall instead of asyncQ.eachSeries --- app/scripts/lib/migrator/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index caa0ef318..0bf88dbec 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -14,9 +14,15 @@ class Migrator { migrateData (versionedData = this.generateInitialState()) { const remaining = this.migrations.filter(migrationIsPending) if (remaining.length === 0) return versionedData + + const migrations = remaining.map((migration, i) => { + if (i === 0) return this.runMigration.bind(this, migration, versionedData) + return this.runMigration.bind(this, migration) + }) + return ( - asyncQ.eachSeries(remaining, (migration) => this.runMigration(versionedData, migration)) - .then((migratedData) => migratedData.pop()) + asyncQ.waterfall(migrations) + .then((migratedData) => Promise.resolve(migratedData)) ) // migration is "pending" if hit has a higher @@ -26,10 +32,10 @@ class Migrator { } } - runMigration (versionedData, migration) { + runMigration (migration, versionedData) { return migration.migrate(versionedData) .then((migratedData) => { - if (!migratedData.data) return Promise.reject(new Error('Migrator - Migration returned empty data')) + 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)