aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/migrator
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-01-12 18:24:33 +0800
committerkumavis <aaron@kumavis.me>2017-01-12 18:24:33 +0800
commit80514d73b5bc6887cea877194091c941cfb9a8e6 (patch)
tree24e051368ffe23fdc126ae30407f79febb4a7760 /app/scripts/lib/migrator
parentb33c51c0a6c7c8a7b0c0a9a6ca101f874f2db3d1 (diff)
downloadtangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar
tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar.gz
tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar.bz2
tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar.lz
tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar.xz
tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.tar.zst
tangerine-wallet-browser-80514d73b5bc6887cea877194091c941cfb9a8e6.zip
migrations - wip - 005 multivault migration
Diffstat (limited to 'app/scripts/lib/migrator')
-rw-r--r--app/scripts/lib/migrator/index.js19
1 files changed, 14 insertions, 5 deletions
diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js
index 02d8c2335..ab5a757b3 100644
--- a/app/scripts/lib/migrator/index.js
+++ b/app/scripts/lib/migrator/index.js
@@ -7,22 +7,31 @@ class Migrator {
this.migrations = migrations.sort((a, b) => a.version - b.version)
let lastMigration = this.migrations.slice(-1)[0]
// use specified defaultVersion or highest migration version
- this.defaultVersion = opts.defaultVersion || lastMigration && lastMigration.version || 0
+ this.defaultVersion = opts.defaultVersion || (lastMigration && lastMigration.version) || 0
}
// run all pending migrations on meta in place
- migrateData (meta = { version: this.defaultVersion }) {
+ migrateData (versionedData = this.generateInitialState()) {
let remaining = this.migrations.filter(migrationIsPending)
return (
- asyncQ.eachSeries(remaining, (migration) => migration.migrate(meta))
- .then(() => meta)
+ asyncQ.eachSeries(remaining, (migration) => migration.migrate(versionedData))
+ .then(() => versionedData)
)
// migration is "pending" if hit has a higher
// version number than currentVersion
function migrationIsPending(migration) {
- return migration.version > meta.version
+ return migration.version > versionedData.meta.version
+ }
+ }
+
+ generateInitialState (initState) {
+ return {
+ meta: {
+ version: this.defaultVersion,
+ },
+ data: initState,
}
}