signal-desktop/js/modules/migrations/run_migrations.js

32 lines
914 B
JavaScript
Raw Normal View History

2018-03-26 19:17:19 +00:00
const isFunction = require('lodash/isFunction');
const isObject = require('lodash/isObject');
const isString = require('lodash/isString');
const { deferredToPromise } = require('../deferred_to_promise');
2018-03-26 19:17:19 +00:00
exports.runMigrations = async ({ Backbone, closeDatabase, database } = {}) => {
2018-03-26 19:17:19 +00:00
if (!isObject(Backbone) || !isObject(Backbone.Collection) ||
!isFunction(Backbone.Collection.extend)) {
throw new TypeError('"Backbone" is required');
}
if (!isFunction(closeDatabase)) {
throw new TypeError('"closeDatabase" is required');
}
2018-03-26 19:17:19 +00:00
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',
}))();
await deferredToPromise(migrationCollection.fetch());
await closeDatabase();
return;
2018-03-26 19:17:19 +00:00
};