Skip migrations that have already been applied
This commit is contained in:
@@ -6,6 +6,7 @@ const isString = require('lodash/isString');
|
|||||||
const head = require('lodash/head');
|
const head = require('lodash/head');
|
||||||
const last = require('lodash/last');
|
const last = require('lodash/last');
|
||||||
|
|
||||||
|
const db = require('../database');
|
||||||
const { deferredToPromise } = require('../deferred_to_promise');
|
const { deferredToPromise } = require('../deferred_to_promise');
|
||||||
|
|
||||||
|
|
||||||
@@ -23,6 +24,25 @@ exports.runMigrations = async ({ Backbone, database } = {}) => {
|
|||||||
throw new TypeError('"database" is required');
|
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({
|
const migrationCollection = new (Backbone.Collection.extend({
|
||||||
database,
|
database,
|
||||||
storeName: 'items',
|
storeName: 'items',
|
||||||
|
Reference in New Issue
Block a user