From 5f220a7b2cf3c2c6faef0bdb8e4bc92cda276dda Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 11 Apr 2018 11:42:06 -0400 Subject: [PATCH] Add migration for media gallery indices --- js/modules/migrations/18/index.js | 16 ++++++++++++++++ ...rations_0_database_with_attachment_data.js | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 js/modules/migrations/18/index.js diff --git a/js/modules/migrations/18/index.js b/js/modules/migrations/18/index.js new file mode 100644 index 000000000..a1072f227 --- /dev/null +++ b/js/modules/migrations/18/index.js @@ -0,0 +1,16 @@ +exports.run = (transaction) => { + const messagesStore = transaction.objectStore('messages'); + + [ + 'numAttachments', + 'numVisualMediaAttachments', + 'numFileAttachments', + ].forEach((name) => { + console.log(`Create message attachment metadata index: '${name}'`); + messagesStore.createIndex( + name, + ['conversationId', 'received_at', name], + { unique: false } + ); + }); +}; diff --git a/js/modules/migrations/migrations_0_database_with_attachment_data.js b/js/modules/migrations/migrations_0_database_with_attachment_data.js index 1f80b48e3..953d8406e 100644 --- a/js/modules/migrations/migrations_0_database_with_attachment_data.js +++ b/js/modules/migrations/migrations_0_database_with_attachment_data.js @@ -1,6 +1,7 @@ const { isString, last } = require('lodash'); const { runMigrations } = require('./run_migrations'); +const Migration18 = require('./18'); // IMPORTANT: The migrations below are run on a database that may be very large @@ -133,7 +134,23 @@ const migrations = [ const duration = Date.now() - start; console.log( - 'Complete migration to database version 17.', + 'Complete migration to database version 17', + `Duration: ${duration}ms` + ); + next(); + }, + }, + { + version: 18, + migrate(transaction, next) { + console.log('Migration 18'); + + const start = Date.now(); + Migration18.run(transaction); + const duration = Date.now() - start; + + console.log( + 'Complete migration to database version 18', `Duration: ${duration}ms` ); next();