Skip migrations that have already been applied
This commit is contained in:
parent
417511ffd2
commit
921c3dba7c
1 changed files with 20 additions and 0 deletions
|
@ -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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue