2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2014-11-13 22:35:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
window.Whisper.Database = window.Whisper.Database || {};
|
|
|
|
window.Whisper.Database.id = window.Whisper.Database.id || 'signal';
|
2015-07-15 21:27:11 +00:00
|
|
|
window.Whisper.Database.nolog = true;
|
2014-11-13 22:35:37 +00:00
|
|
|
|
|
|
|
Whisper.Database.migrations = [
|
|
|
|
{
|
2017-04-18 06:30:25 +00:00
|
|
|
version: "12.0",
|
2014-11-13 22:35:37 +00:00
|
|
|
migrate: function(transaction, next) {
|
2014-12-12 03:41:40 +00:00
|
|
|
console.log('migration 1.0');
|
2016-02-13 01:18:36 +00:00
|
|
|
console.log('creating object stores');
|
2014-11-13 22:35:37 +00:00
|
|
|
var messages = transaction.db.createObjectStore("messages");
|
2014-12-12 03:41:40 +00:00
|
|
|
messages.createIndex("conversation", ["conversationId", "received_at"], { unique: false });
|
|
|
|
messages.createIndex("receipt", "sent_at", { unique: false });
|
2017-04-18 06:30:25 +00:00
|
|
|
messages.createIndex('unread', ['conversationId', 'unread'], { unique: false });
|
|
|
|
messages.createIndex('expires_at', 'expires_at', { unique: false });
|
2014-11-13 22:35:37 +00:00
|
|
|
|
|
|
|
var conversations = transaction.db.createObjectStore("conversations");
|
2014-12-12 03:41:40 +00:00
|
|
|
conversations.createIndex("inbox", "active_at", { unique: false });
|
|
|
|
conversations.createIndex("group", "members", { unique: false, multiEntry: true });
|
2015-01-28 12:17:46 +00:00
|
|
|
conversations.createIndex("type", "type", { unique: false });
|
2017-04-18 06:30:25 +00:00
|
|
|
conversations.createIndex("search", "tokens", { unique: false, multiEntry: true });
|
2015-04-01 20:08:09 +00:00
|
|
|
|
2015-05-06 22:09:03 +00:00
|
|
|
var groups = transaction.db.createObjectStore('groups');
|
|
|
|
|
2015-05-05 03:26:26 +00:00
|
|
|
var sessions = transaction.db.createObjectStore('sessions');
|
|
|
|
var identityKeys = transaction.db.createObjectStore('identityKeys');
|
2015-04-01 20:08:09 +00:00
|
|
|
var preKeys = transaction.db.createObjectStore("preKeys");
|
|
|
|
var signedPreKeys = transaction.db.createObjectStore("signedPreKeys");
|
2015-05-11 22:40:21 +00:00
|
|
|
var items = transaction.db.createObjectStore("items");
|
2015-11-20 01:19:04 +00:00
|
|
|
|
2016-02-13 01:18:36 +00:00
|
|
|
console.log('creating debug log');
|
2017-04-18 06:30:25 +00:00
|
|
|
var debugLog = transaction.db.createObjectStore("debug");
|
|
|
|
|
2017-03-02 01:57:34 +00:00
|
|
|
next();
|
|
|
|
}
|
2017-05-24 20:14:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
version: "13.0",
|
|
|
|
migrate: function(transaction, next) {
|
|
|
|
console.log('migration 13.0');
|
|
|
|
console.log('Adding fields to identity keys');
|
|
|
|
var identityKeys = transaction.objectStore('identityKeys');
|
|
|
|
var request = identityKeys.openCursor();
|
|
|
|
var promises = [];
|
|
|
|
request.onsuccess = function(event) {
|
|
|
|
var cursor = event.target.result;
|
|
|
|
if (cursor) {
|
|
|
|
var attributes = cursor.value;
|
|
|
|
attributes.timestamp = 0;
|
|
|
|
attributes.firstUse = false;
|
|
|
|
attributes.nonblockingApproval = false;
|
2017-06-12 19:55:16 +00:00
|
|
|
attributes.verified = 0;
|
2017-05-24 20:14:56 +00:00
|
|
|
promises.push(new Promise(function(resolve, reject) {
|
|
|
|
var putRequest = identityKeys.put(attributes, attributes.id);
|
|
|
|
putRequest.onsuccess = resolve;
|
|
|
|
putRequest.onerror = function(e) {
|
|
|
|
console.log(e);
|
|
|
|
reject(e);
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
cursor.continue();
|
|
|
|
} else {
|
|
|
|
// no more results
|
|
|
|
Promise.all(promises).then(function() {
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
request.onerror = function(event) {
|
|
|
|
console.log(event);
|
|
|
|
};
|
|
|
|
}
|
2017-07-17 22:46:00 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
version: "14.0",
|
|
|
|
migrate: function(transaction, next) {
|
|
|
|
console.log('migration 14.0');
|
|
|
|
console.log('Adding unprocessed message store');
|
|
|
|
var unprocessed = transaction.db.createObjectStore('unprocessed');
|
|
|
|
unprocessed.createIndex('received', 'timestamp', { unique: false });
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
version: "15.0",
|
|
|
|
migrate: function(transaction, next) {
|
|
|
|
console.log('migration 15.0');
|
|
|
|
console.log('Adding messages index for de-duplication');
|
|
|
|
var messages = transaction.objectStore('messages');
|
|
|
|
messages.createIndex('unique', ['source', 'sourceDevice', 'sent_at'], { unique: true });
|
|
|
|
next();
|
|
|
|
}
|
2017-09-25 22:00:19 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
version: "16.0",
|
|
|
|
migrate: function(transaction, next) {
|
|
|
|
console.log('migration 16.0');
|
|
|
|
console.log('Dropping log table, since we now log to disk');
|
|
|
|
var messages = transaction.db.deleteObjectStore('debug');
|
|
|
|
next();
|
|
|
|
}
|
2014-11-13 22:35:37 +00:00
|
|
|
}
|
2017-09-25 22:00:19 +00:00
|
|
|
|
2014-11-13 22:35:37 +00:00
|
|
|
];
|
|
|
|
}());
|