From 921c3dba7ca18ad4ba284d6f86bee5ec343c54fa Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 28 Mar 2018 13:10:54 -0400 Subject: [PATCH] Skip migrations that have already been applied --- js/modules/migrations/run_migrations.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/modules/migrations/run_migrations.js b/js/modules/migrations/run_migrations.js index 84635542a..b66057c19 100644 --- a/js/modules/migrations/run_migrations.js +++ b/js/modules/migrations/run_migrations.js @@ -6,6 +6,7 @@ const isString = require('lodash/isString'); const head = require('lodash/head'); const last = require('lodash/last'); +const db = require('../database'); const { deferredToPromise } = require('../deferred_to_promise'); @@ -23,6 +24,25 @@ exports.runMigrations = async ({ Backbone, database } = {}) => { throw new TypeError('"database" is required'); } + const { + firstVersion: firstMigrationVersion, + lastVersion: lastMigrationVersion, + } = getMigrationVersions(database); + + const databaseVersion = await db.getVersion(database.id); + const isAlreadyUpgraded = databaseVersion >= lastMigrationVersion; + + console.log('Database state', { + firstMigrationVersion, + lastMigrationVersion, + databaseVersion, + isAlreadyUpgraded, + }); + + if (isAlreadyUpgraded) { + return; + } + const migrationCollection = new (Backbone.Collection.extend({ database, storeName: 'items',