1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00

fix migrator

This commit is contained in:
frankiebee 2017-05-11 10:10:50 +02:00
parent 03d454f73b
commit 1772d34e94

View File

@ -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) {