aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
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
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')
-rw-r--r--app/scripts/lib/migrations.js18
-rw-r--r--app/scripts/lib/migrator/index.js19
2 files changed, 14 insertions, 23 deletions
diff --git a/app/scripts/lib/migrations.js b/app/scripts/lib/migrations.js
deleted file mode 100644
index 12f60def1..000000000
--- a/app/scripts/lib/migrations.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/* The migrator has two methods the user should be concerned with:
- *
- * getData(), which returns the app-consumable data object
- * saveData(), which persists the app-consumable data object.
- */
-
-// Migrations must start at version 1 or later.
-// They are objects with a `version` number
-// and a `migrate` function.
-//
-// The `migrate` function receives the previous
-// config data format, and returns the new one.
-
-module.exports = [
- require('../migrations/002'),
- require('../migrations/003'),
- require('../migrations/004'),
-]
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,
}
}