Move all remaining stores to SQLCipher
This commit is contained in:
parent
7aa9031c7f
commit
1755e0adfd
25 changed files with 2464 additions and 2047 deletions
|
@ -1,13 +1,13 @@
|
|||
/* global window, Whisper */
|
||||
|
||||
const Migrations0DatabaseWithAttachmentData = require('./migrations_0_database_with_attachment_data');
|
||||
const Migrations = require('./migrations');
|
||||
|
||||
exports.getPlaceholderMigrations = () => {
|
||||
const last0MigrationVersion = Migrations0DatabaseWithAttachmentData.getLatestVersion();
|
||||
const version = Migrations.getLatestVersion();
|
||||
|
||||
return [
|
||||
{
|
||||
version: last0MigrationVersion,
|
||||
version,
|
||||
migrate() {
|
||||
throw new Error(
|
||||
'Unexpected invocation of placeholder migration!' +
|
||||
|
|
|
@ -170,8 +170,19 @@ const migrations = [
|
|||
migrate(transaction, next) {
|
||||
window.log.info('Migration 19');
|
||||
|
||||
// Empty because we don't want to cause incompatibility with beta users who have
|
||||
// already run migration 19 when it was object store removal.
|
||||
|
||||
next();
|
||||
},
|
||||
},
|
||||
{
|
||||
version: 20,
|
||||
migrate(transaction, next) {
|
||||
window.log.info('Migration 20');
|
||||
|
||||
// Empty because we don't want to cause incompatibility with users who have already
|
||||
// run migration 19 when it was the object store removal.
|
||||
// run migration 20 when it was object store removal.
|
||||
|
||||
next();
|
||||
},
|
|
@ -1,84 +0,0 @@
|
|||
/* global window */
|
||||
|
||||
const { last, includes } = require('lodash');
|
||||
|
||||
const { open } = require('../database');
|
||||
const settings = require('../settings');
|
||||
const { runMigrations } = require('./run_migrations');
|
||||
|
||||
// These are cleanup migrations, to be run after migration to SQLCipher
|
||||
exports.migrations = [
|
||||
{
|
||||
version: 20,
|
||||
migrate(transaction, next) {
|
||||
window.log.info('Migration 20');
|
||||
|
||||
const { db } = transaction;
|
||||
|
||||
// This should be run after things are migrated to SQLCipher
|
||||
|
||||
// We check for existence first, because this removal was present in v1.17.0.beta.1,
|
||||
// but reverted in v1.17.0-beta.3
|
||||
|
||||
if (includes(db.objectStoreNames, 'messages')) {
|
||||
window.log.info('Removing messages store');
|
||||
db.deleteObjectStore('messages');
|
||||
}
|
||||
if (includes(db.objectStoreNames, 'unprocessed')) {
|
||||
window.log.info('Removing unprocessed store');
|
||||
db.deleteObjectStore('unprocessed');
|
||||
}
|
||||
if (includes(db.objectStoreNames, 'conversations')) {
|
||||
window.log.info('Removing conversations store');
|
||||
db.deleteObjectStore('conversations');
|
||||
}
|
||||
|
||||
next();
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
exports.run = async ({ Backbone, logger } = {}) => {
|
||||
const database = {
|
||||
id: 'signal',
|
||||
nolog: true,
|
||||
migrations: exports.migrations,
|
||||
};
|
||||
|
||||
const { canRun } = await exports.getStatus({ database });
|
||||
if (!canRun) {
|
||||
throw new Error(
|
||||
'Cannot run migrations on database without attachment data'
|
||||
);
|
||||
}
|
||||
|
||||
await runMigrations({
|
||||
Backbone,
|
||||
logger,
|
||||
database,
|
||||
});
|
||||
};
|
||||
|
||||
exports.getStatus = async ({ database } = {}) => {
|
||||
const connection = await open(database.id, database.version);
|
||||
const isAttachmentMigrationComplete = await settings.isAttachmentMigrationComplete(
|
||||
connection
|
||||
);
|
||||
const hasMigrations = exports.migrations.length > 0;
|
||||
|
||||
const canRun = isAttachmentMigrationComplete && hasMigrations;
|
||||
return {
|
||||
isAttachmentMigrationComplete,
|
||||
hasMigrations,
|
||||
canRun,
|
||||
};
|
||||
};
|
||||
|
||||
exports.getLatestVersion = () => {
|
||||
const lastMigration = last(exports.migrations);
|
||||
if (!lastMigration) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return lastMigration.version;
|
||||
};
|
|
@ -52,7 +52,10 @@ exports.runMigrations = async ({ Backbone, database, logger } = {}) => {
|
|||
storeName: 'items',
|
||||
}))();
|
||||
|
||||
// Note: this legacy migration technique is required to bring old clients with
|
||||
// data in IndexedDB forward into the new world of SQLCipher only.
|
||||
await deferredToPromise(migrationCollection.fetch({ limit: 1 }));
|
||||
|
||||
logger.info('Close database connection');
|
||||
await closeDatabaseConnection({ Backbone });
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue