From 77f8995568d64aa2d9acd878b43fdeb1e7c3bafb Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 3 Feb 2017 14:00:30 -0800 Subject: migrations - fix migration #9 and add safety checks to migrator --- app/scripts/lib/migrator/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index ab5a757b3..312345263 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -15,7 +15,7 @@ class Migrator { let remaining = this.migrations.filter(migrationIsPending) return ( - asyncQ.eachSeries(remaining, (migration) => migration.migrate(versionedData)) + asyncQ.eachSeries(remaining, (migration) => this.runMigration(versionedData, migration)) .then(() => versionedData) ) @@ -26,6 +26,17 @@ 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) + }) + ) + } + generateInitialState (initState) { return { meta: { -- cgit v1.2.3