Manually close database connection after migration
This commit is contained in:
parent
106ce21c49
commit
da144edc56
4 changed files with 31 additions and 16 deletions
|
@ -11,7 +11,8 @@
|
||||||
/* global Whisper: false */
|
/* global Whisper: false */
|
||||||
/* global wrapDeferred: false */
|
/* global wrapDeferred: false */
|
||||||
|
|
||||||
;(async function() {
|
|
||||||
|
;(/* jshint ignore:start */ async /* jshint ignore:end */function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { IdleDetector, MessageDataMigrator } = Signal.Workflow;
|
const { IdleDetector, MessageDataMigrator } = Signal.Workflow;
|
||||||
|
@ -85,14 +86,11 @@
|
||||||
console.log('Start IndexedDB migrations');
|
console.log('Start IndexedDB migrations');
|
||||||
|
|
||||||
console.log('Migrate database with attachments');
|
console.log('Migrate database with attachments');
|
||||||
const closeDatabase = () =>
|
await Migrations0DatabaseWithAttachmentData.run({ Backbone });
|
||||||
Whisper.Database.close();
|
|
||||||
await Migrations0DatabaseWithAttachmentData.run({ Backbone, closeDatabase });
|
|
||||||
|
|
||||||
console.log('Migrate database without attachments');
|
console.log('Migrate database without attachments');
|
||||||
await Migrations1DatabaseWithoutAttachmentData.run({
|
await Migrations1DatabaseWithoutAttachmentData.run({
|
||||||
Backbone,
|
Backbone,
|
||||||
closeDatabase,
|
|
||||||
Database: Whisper.Database,
|
Database: Whisper.Database,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -145,5 +145,5 @@ const database = {
|
||||||
migrations,
|
migrations,
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.run = ({ Backbone, closeDatabase } = {}) =>
|
exports.run = ({ Backbone } = {}) =>
|
||||||
runMigrations({ Backbone, closeDatabase, database });
|
runMigrations({ Backbone, database });
|
||||||
|
|
|
@ -11,5 +11,5 @@ exports.migrations = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
exports.run = ({ Backbone, closeDatabase, Database } = {}) =>
|
exports.run = ({ Backbone, Database } = {}) =>
|
||||||
runMigrations({ Backbone, closeDatabase, database: Database });
|
runMigrations({ Backbone, database: Database });
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* eslint-env browser */
|
||||||
|
|
||||||
const isFunction = require('lodash/isFunction');
|
const isFunction = require('lodash/isFunction');
|
||||||
const isObject = require('lodash/isObject');
|
const isObject = require('lodash/isObject');
|
||||||
const isString = require('lodash/isString');
|
const isString = require('lodash/isString');
|
||||||
|
@ -5,16 +7,32 @@ const isString = require('lodash/isString');
|
||||||
const { deferredToPromise } = require('../deferred_to_promise');
|
const { deferredToPromise } = require('../deferred_to_promise');
|
||||||
|
|
||||||
|
|
||||||
exports.runMigrations = async ({ Backbone, closeDatabase, database } = {}) => {
|
const closeDatabase = name =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const request = window.indexedDB.open(name);
|
||||||
|
request.onblocked = () => {
|
||||||
|
reject(new Error(`Database '${name}' blocked`));
|
||||||
|
};
|
||||||
|
request.onupgradeneeded = (event) => {
|
||||||
|
reject(new Error('Unexpected database upgraded needed:' +
|
||||||
|
` oldVersion: ${event.oldVersion}, newVersion: ${event.newVersion}`));
|
||||||
|
};
|
||||||
|
request.onerror = (event) => {
|
||||||
|
reject(event.target.error);
|
||||||
|
};
|
||||||
|
request.onsuccess = (event) => {
|
||||||
|
const connection = event.target.result;
|
||||||
|
connection.close();
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.runMigrations = async ({ Backbone, database } = {}) => {
|
||||||
if (!isObject(Backbone) || !isObject(Backbone.Collection) ||
|
if (!isObject(Backbone) || !isObject(Backbone.Collection) ||
|
||||||
!isFunction(Backbone.Collection.extend)) {
|
!isFunction(Backbone.Collection.extend)) {
|
||||||
throw new TypeError('"Backbone" is required');
|
throw new TypeError('"Backbone" is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFunction(closeDatabase)) {
|
|
||||||
throw new TypeError('"closeDatabase" is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isObject(database) || !isString(database.id) ||
|
if (!isObject(database) || !isString(database.id) ||
|
||||||
!Array.isArray(database.migrations)) {
|
!Array.isArray(database.migrations)) {
|
||||||
throw new TypeError('"database" is required');
|
throw new TypeError('"database" is required');
|
||||||
|
@ -26,6 +44,5 @@ exports.runMigrations = async ({ Backbone, closeDatabase, database } = {}) => {
|
||||||
}))();
|
}))();
|
||||||
|
|
||||||
await deferredToPromise(migrationCollection.fetch());
|
await deferredToPromise(migrationCollection.fetch());
|
||||||
await closeDatabase();
|
await closeDatabase(database.id);
|
||||||
return;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue