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 });
|
await Migrations0DatabaseWithAttachmentData.run({ Backbone });
|
||||||
|
|
||||||
console.log('Migrate attachments to disk');
|
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');
|
console.log('Migrate database without attachments');
|
||||||
await Migrations1DatabaseWithoutAttachmentData.run({
|
await Migrations1DatabaseWithoutAttachmentData.run({
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
/* eslint-env browser */
|
/* eslint-env browser */
|
||||||
|
|
||||||
// Module to upgrade the schema of messages, e.g. migrate attachments to disk.
|
// Module to upgrade the schema of messages, e.g. migrate attachments to disk.
|
||||||
// `processAll` is meant to be run after the initial database migrations
|
// `processAll` purposely doesn’t rely on our Backbone IndexedDB adapter to
|
||||||
// (12 – 17) and purposely doesn’t rely on our Backbone IndexedDB adapter to
|
// prevent automatic migrations. Rather, it uses direct IndexedDB access.
|
||||||
// prevent subsequent migrations to run (18+) but rather uses direct IndexedDB
|
// This includes avoiding usage of `storage` module which uses Backbone under
|
||||||
// access. This includes avoiding usage of `storage` module which uses Backbone
|
// the hood.
|
||||||
// under the hood.
|
|
||||||
|
|
||||||
const isFunction = require('lodash/isFunction');
|
const isFunction = require('lodash/isFunction');
|
||||||
const isNumber = require('lodash/isNumber');
|
const isNumber = require('lodash/isNumber');
|
||||||
|
@ -17,9 +16,6 @@ const Message = require('./types/message');
|
||||||
const { deferredToPromise } = require('./deferred_to_promise');
|
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 MESSAGES_STORE_NAME = 'messages';
|
||||||
const ITEMS_STORE_NAME = 'items';
|
const ITEMS_STORE_NAME = 'items';
|
||||||
const NUM_MESSAGES_PER_BATCH = 50;
|
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)) {
|
if (!isObject(Backbone)) {
|
||||||
throw new TypeError('"Backbone" is required');
|
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)) {
|
if (!isFunction(upgradeMessageSchema)) {
|
||||||
throw new TypeError('"upgradeMessageSchema" is required');
|
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);
|
const isComplete = await isMigrationComplete(connection);
|
||||||
console.log('Is attachment migration complete?', isComplete);
|
console.log('Is attachment migration complete?', isComplete);
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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');
|
||||||
|
const last = require('lodash/last');
|
||||||
|
|
||||||
const { runMigrations } = require('./run_migrations');
|
const { runMigrations } = require('./run_migrations');
|
||||||
|
|
||||||
|
@ -169,3 +170,8 @@ exports.createCollection = ({ Backbone, storeName }) => {
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getDatabase = () => ({
|
||||||
|
name: database.id,
|
||||||
|
version: last(migrations).version,
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue