Remove hard-coded database connection settings
This commit is contained in:
parent
1df6dc8378
commit
eca930770c
3 changed files with 32 additions and 11 deletions
|
@ -87,7 +87,13 @@
|
|||
await Migrations0DatabaseWithAttachmentData.run({ Backbone });
|
||||
|
||||
console.log('Migrate attachments to disk');
|
||||
await MessageDataMigrator.processAll({ Backbone, upgradeMessageSchema });
|
||||
const database = Migrations0DatabaseWithAttachmentData.getDatabase();
|
||||
await MessageDataMigrator.processAll({
|
||||
Backbone,
|
||||
databaseName: database.name,
|
||||
databaseVersion: database.version,
|
||||
upgradeMessageSchema,
|
||||
});
|
||||
|
||||
console.log('Migrate database without attachments');
|
||||
await Migrations1DatabaseWithoutAttachmentData.run({
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
/* eslint-env browser */
|
||||
|
||||
// Module to upgrade the schema of messages, e.g. migrate attachments to disk.
|
||||
// `processAll` is meant to be run after the initial database migrations
|
||||
// (12 – 17) and purposely doesn’t rely on our Backbone IndexedDB adapter to
|
||||
// prevent subsequent migrations to run (18+) but rather uses direct IndexedDB
|
||||
// access. This includes avoiding usage of `storage` module which uses Backbone
|
||||
// under the hood.
|
||||
// `processAll` purposely doesn’t rely on our Backbone IndexedDB adapter to
|
||||
// prevent automatic migrations. Rather, it uses direct IndexedDB access.
|
||||
// This includes avoiding usage of `storage` module which uses Backbone under
|
||||
// the hood.
|
||||
|
||||
const isFunction = require('lodash/isFunction');
|
||||
const isNumber = require('lodash/isNumber');
|
||||
|
@ -17,9 +16,6 @@ const Message = require('./types/message');
|
|||
const { deferredToPromise } = require('./deferred_to_promise');
|
||||
|
||||
|
||||
const DATABASE_NAME = 'signal';
|
||||
// Last version with attachment data stored in database:
|
||||
const EXPECTED_DATABASE_VERSION = 17;
|
||||
const MESSAGES_STORE_NAME = 'messages';
|
||||
const ITEMS_STORE_NAME = 'items';
|
||||
const NUM_MESSAGES_PER_BATCH = 50;
|
||||
|
@ -77,16 +73,29 @@ exports.processNext = async ({
|
|||
};
|
||||
};
|
||||
|
||||
exports.processAll = async ({ Backbone, upgradeMessageSchema } = {}) => {
|
||||
exports.processAll = async ({
|
||||
Backbone,
|
||||
databaseName,
|
||||
databaseVersion,
|
||||
upgradeMessageSchema,
|
||||
} = {}) => {
|
||||
if (!isObject(Backbone)) {
|
||||
throw new TypeError('"Backbone" is required');
|
||||
}
|
||||
|
||||
if (!isString(databaseName)) {
|
||||
throw new TypeError('"databaseName" must be a string');
|
||||
}
|
||||
|
||||
if (!isNumber(databaseVersion)) {
|
||||
throw new TypeError('"databaseVersion" must be a number');
|
||||
}
|
||||
|
||||
if (!isFunction(upgradeMessageSchema)) {
|
||||
throw new TypeError('"upgradeMessageSchema" is required');
|
||||
}
|
||||
|
||||
const connection = await openDatabase(DATABASE_NAME, EXPECTED_DATABASE_VERSION);
|
||||
const connection = await openDatabase(databaseName, databaseVersion);
|
||||
const isComplete = await isMigrationComplete(connection);
|
||||
console.log('Is attachment migration complete?', isComplete);
|
||||
if (isComplete) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const isFunction = require('lodash/isFunction');
|
||||
const isObject = require('lodash/isObject');
|
||||
const isString = require('lodash/isString');
|
||||
const last = require('lodash/last');
|
||||
|
||||
const { runMigrations } = require('./run_migrations');
|
||||
|
||||
|
@ -169,3 +170,8 @@ exports.createCollection = ({ Backbone, storeName }) => {
|
|||
|
||||
return collection;
|
||||
};
|
||||
|
||||
exports.getDatabase = () => ({
|
||||
name: database.id,
|
||||
version: last(migrations).version,
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue