Migrate from IndexedDB before doing new version checks
This commit is contained in:
parent
45f2bef8fe
commit
569acb091c
2 changed files with 37 additions and 24 deletions
|
@ -197,11 +197,15 @@
|
||||||
|
|
||||||
const cancelInitializationMessage = Views.Initialization.setMessage();
|
const cancelInitializationMessage = Views.Initialization.setMessage();
|
||||||
|
|
||||||
const isIndexedDBPresent = await doesDatabaseExist();
|
const version = await window.Signal.Data.getItemById('version');
|
||||||
if (isIndexedDBPresent) {
|
let isIndexedDBPresent = false;
|
||||||
window.installStorage(window.legacyStorage);
|
if (!version) {
|
||||||
window.log.info('Start IndexedDB migrations');
|
isIndexedDBPresent = await doesDatabaseExist();
|
||||||
await runMigrations();
|
if (isIndexedDBPresent) {
|
||||||
|
window.installStorage(window.legacyStorage);
|
||||||
|
window.log.info('Start IndexedDB migrations');
|
||||||
|
await runMigrations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.log.info('Storage fetch');
|
window.log.info('Storage fetch');
|
||||||
|
@ -327,6 +331,24 @@
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isIndexedDBPresent) {
|
||||||
|
await mandatoryMessageUpgrade({ upgradeMessageSchema });
|
||||||
|
await migrateAllToSQLCipher({ writeNewAttachmentData, Views });
|
||||||
|
await removeDatabase();
|
||||||
|
try {
|
||||||
|
await window.Signal.Data.removeIndexedDBFiles();
|
||||||
|
} catch (error) {
|
||||||
|
window.log.error(
|
||||||
|
'Failed to remove IndexedDB files:',
|
||||||
|
error && error.stack ? error.stack : error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.installStorage(window.newStorage);
|
||||||
|
await window.storage.fetch();
|
||||||
|
await storage.put('indexeddb-delete-needed', true);
|
||||||
|
}
|
||||||
|
|
||||||
const currentVersion = window.getVersion();
|
const currentVersion = window.getVersion();
|
||||||
const lastVersion = storage.get('version');
|
const lastVersion = storage.get('version');
|
||||||
newVersion = !lastVersion || currentVersion !== lastVersion;
|
newVersion = !lastVersion || currentVersion !== lastVersion;
|
||||||
|
@ -362,27 +384,10 @@
|
||||||
if (window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5')) {
|
if (window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5')) {
|
||||||
await window.Signal.Logs.deleteAll();
|
await window.Signal.Logs.deleteAll();
|
||||||
window.restart();
|
window.restart();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isIndexedDBPresent) {
|
|
||||||
await mandatoryMessageUpgrade({ upgradeMessageSchema });
|
|
||||||
await migrateAllToSQLCipher({ writeNewAttachmentData, Views });
|
|
||||||
await removeDatabase();
|
|
||||||
try {
|
|
||||||
await window.Signal.Data.removeIndexedDBFiles();
|
|
||||||
} catch (error) {
|
|
||||||
window.log.error(
|
|
||||||
'Failed to remove IndexedDB files:',
|
|
||||||
error && error.stack ? error.stack : error
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.installStorage(window.newStorage);
|
|
||||||
await window.storage.fetch();
|
|
||||||
await storage.put('indexeddb-delete-needed', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Views.Initialization.setMessage(window.i18n('optimizingApplication'));
|
Views.Initialization.setMessage(window.i18n('optimizingApplication'));
|
||||||
|
|
||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global window, Whisper, textsecure */
|
/* global window, Whisper, textsecure, setTimeout */
|
||||||
|
|
||||||
const { isFunction } = require('lodash');
|
const { isFunction } = require('lodash');
|
||||||
|
|
||||||
|
@ -142,12 +142,20 @@ async function migrateAllToSQLCipher({ writeNewAttachmentData, Views } = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doesDatabaseExist() {
|
async function doesDatabaseExist() {
|
||||||
|
window.log.info('Checking for the existence of IndexedDB data...');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const { id } = Whisper.Database;
|
const { id } = Whisper.Database;
|
||||||
const req = window.indexedDB.open(id);
|
const req = window.indexedDB.open(id);
|
||||||
|
|
||||||
let existed = true;
|
let existed = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
window.log.warn(
|
||||||
|
'doesDatabaseExist: Timed out attempting to check IndexedDB status'
|
||||||
|
);
|
||||||
|
return resolve(false);
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
req.onerror = reject;
|
req.onerror = reject;
|
||||||
req.onsuccess = () => {
|
req.onsuccess = () => {
|
||||||
req.result.close();
|
req.result.close();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue