Extract getMigrationVersions
This commit is contained in:
parent
6aea36240d
commit
c5c94bc3ab
1 changed files with 16 additions and 0 deletions
|
@ -3,6 +3,8 @@
|
|||
const isFunction = require('lodash/isFunction');
|
||||
const isObject = require('lodash/isObject');
|
||||
const isString = require('lodash/isString');
|
||||
const head = require('lodash/head');
|
||||
const last = require('lodash/last');
|
||||
|
||||
const { deferredToPromise } = require('../deferred_to_promise');
|
||||
|
||||
|
@ -30,3 +32,17 @@ exports.runMigrations = async ({ Backbone, database } = {}) => {
|
|||
console.log('Close database connection');
|
||||
await closeDatabaseConnection({ Backbone });
|
||||
};
|
||||
|
||||
const getMigrationVersions = (database) => {
|
||||
if (!isObject(database) || !Array.isArray(database.migrations)) {
|
||||
throw new TypeError('"database" is required');
|
||||
}
|
||||
|
||||
const firstMigration = head(database.migrations);
|
||||
const lastMigration = last(database.migrations);
|
||||
|
||||
const firstVersion = firstMigration ? parseInt(firstMigration.version, 10) : null;
|
||||
const lastVersion = lastMigration ? parseInt(lastMigration.version, 10) : null;
|
||||
|
||||
return { firstVersion, lastVersion };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue