aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/migrator
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-05-11 16:46:17 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-05-12 05:25:33 +0800
commit6c01b26845cfb8e113d3016ebd595a9098623f62 (patch)
treeabe75992ac93e900643895396b16bc92af4fffc9 /app/scripts/lib/migrator
parent1772d34e947ec5e940cc99f53ff0a102e048d69c (diff)
downloadtangerine-wallet-browser-6c01b26845cfb8e113d3016ebd595a9098623f62.tar
tangerine-wallet-browser-6c01b26845cfb8e113d3016ebd595a9098623f62.tar.gz
tangerine-wallet-browser-6c01b26845cfb8e113d3016ebd595a9098623f62.tar.bz2
tangerine-wallet-browser-6c01b26845cfb8e113d3016ebd595a9098623f62.tar.lz
tangerine-wallet-browser-6c01b26845cfb8e113d3016ebd595a9098623f62.tar.xz
tangerine-wallet-browser-6c01b26845cfb8e113d3016ebd595a9098623f62.tar.zst
tangerine-wallet-browser-6c01b26845cfb8e113d3016ebd595a9098623f62.zip
use asyncQ.waterfall instead of asyncQ.eachSeries
Diffstat (limited to 'app/scripts/lib/migrator')
-rw-r--r--app/scripts/lib/migrator/index.js14
1 files 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)