Extract runMigrations
This commit is contained in:
parent
d16178638e
commit
d7c8d33edb
2 changed files with 30 additions and 19 deletions
|
@ -1,5 +1,4 @@
|
|||
const isFunction = require('lodash/isFunction');
|
||||
const isObject = require('lodash/isObject');
|
||||
const { runMigrations } = require('./run_migrations');
|
||||
|
||||
|
||||
// IMPORTANT: The migrations below are run on a database that may be very large
|
||||
|
@ -147,20 +146,5 @@ const database = {
|
|||
migrations,
|
||||
};
|
||||
|
||||
exports.run = ({ Backbone } = {}) => {
|
||||
if (!isObject(Backbone) || !isObject(Backbone.Collection) ||
|
||||
!isFunction(Backbone.Collection.extend)) {
|
||||
throw new TypeError('"Backbone" is required');
|
||||
}
|
||||
|
||||
const migrationCollection = new (Backbone.Collection.extend({
|
||||
database,
|
||||
storeName: 'conversations',
|
||||
}))();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// NOTE: This `then` refers to a jQuery `Deferred`:
|
||||
// eslint-disable-next-line more/no-then
|
||||
migrationCollection.fetch().then(() => resolve());
|
||||
});
|
||||
};
|
||||
exports.run = ({ Backbone } = {}) =>
|
||||
runMigrations({ Backbone, database });
|
||||
|
|
27
js/modules/migrations/run_migrations.js
Normal file
27
js/modules/migrations/run_migrations.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const isFunction = require('lodash/isFunction');
|
||||
const isObject = require('lodash/isObject');
|
||||
const isString = require('lodash/isString');
|
||||
|
||||
|
||||
exports.runMigrations = ({ Backbone, database } = {}) => {
|
||||
if (!isObject(Backbone) || !isObject(Backbone.Collection) ||
|
||||
!isFunction(Backbone.Collection.extend)) {
|
||||
throw new TypeError('"Backbone" is required');
|
||||
}
|
||||
|
||||
if (!isObject(database) || !isString(database.id) ||
|
||||
!Array.isArray(database.migrations)) {
|
||||
throw new TypeError('"database" is required');
|
||||
}
|
||||
|
||||
const migrationCollection = new (Backbone.Collection.extend({
|
||||
database,
|
||||
storeName: 'items',
|
||||
}))();
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// NOTE: This `then` refers to a jQuery `Deferred`:
|
||||
// eslint-disable-next-line more/no-then
|
||||
migrationCollection.fetch().then(() => resolve());
|
||||
});
|
||||
};
|
Loading…
Reference in a new issue