aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/migrator
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-05-11 16:10:50 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-05-11 16:10:50 +0800
commit1772d34e947ec5e940cc99f53ff0a102e048d69c (patch)
treefd290b5a1d919647e548f36b3aa1008f4ab39a68 /app/scripts/lib/migrator
parent03d454f73baa27f9b44ec4bee0ba8f3c71414aa6 (diff)
downloadtangerine-wallet-browser-1772d34e947ec5e940cc99f53ff0a102e048d69c.tar
tangerine-wallet-browser-1772d34e947ec5e940cc99f53ff0a102e048d69c.tar.gz
tangerine-wallet-browser-1772d34e947ec5e940cc99f53ff0a102e048d69c.tar.bz2
tangerine-wallet-browser-1772d34e947ec5e940cc99f53ff0a102e048d69c.tar.lz
tangerine-wallet-browser-1772d34e947ec5e940cc99f53ff0a102e048d69c.tar.xz
tangerine-wallet-browser-1772d34e947ec5e940cc99f53ff0a102e048d69c.tar.zst
tangerine-wallet-browser-1772d34e947ec5e940cc99f53ff0a102e048d69c.zip
fix migrator
Diffstat (limited to 'app/scripts/lib/migrator')
-rw-r--r--app/scripts/lib/migrator/index.js17
1 files changed, 8 insertions, 9 deletions
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) {