call cursor.update during backup field migration, needs new version

This commit is contained in:
Bruno Windels 2022-02-01 12:31:10 +01:00
parent 00c5e747d2
commit 2e3616e05d

View file

@ -33,7 +33,8 @@ export const schema: MigrationFunc[] = [
changeSSSSKeyPrefix, changeSSSSKeyPrefix,
backupAndRestoreE2EEAccountToLocalStorage, backupAndRestoreE2EEAccountToLocalStorage,
clearAllStores, clearAllStores,
addInboundSessionBackupIndex addInboundSessionBackupIndex,
migrateBackupStatus
]; ];
// TODO: how to deal with git merge conflicts of this array? // TODO: how to deal with git merge conflicts of this array?
@ -280,6 +281,13 @@ async function clearAllStores(db: IDBDatabase, txn: IDBTransaction) {
// v15 add backup index to inboundGroupSessions // v15 add backup index to inboundGroupSessions
async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction, localStorage: IDOMStorage, log: ILogItem): Promise<void> { async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction, localStorage: IDOMStorage, log: ILogItem): Promise<void> {
const inboundGroupSessions = txn.objectStore("inboundGroupSessions");
inboundGroupSessions.createIndex("byBackup", "backup", {unique: false});
}
// v16 migrates the backup and source fields of inbound group sessions
async function migrateBackupStatus(db: IDBDatabase, txn: IDBTransaction, localStorage: IDOMStorage, log: ILogItem): Promise<void> {
const inboundGroupSessions = txn.objectStore("inboundGroupSessions"); const inboundGroupSessions = txn.objectStore("inboundGroupSessions");
let countWithSession = 0; let countWithSession = 0;
let countWithoutSession = 0; let countWithoutSession = 0;
@ -291,6 +299,7 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction
// to backup keys that were already in backup, which // to backup keys that were already in backup, which
// the server will ignore // the server will ignore
value.source = KeySource.DeviceMessage; value.source = KeySource.DeviceMessage;
cursor.update(value);
countWithSession += 1; countWithSession += 1;
} else { } else {
countWithoutSession += 1; countWithoutSession += 1;
@ -299,5 +308,4 @@ async function addInboundSessionBackupIndex(db: IDBDatabase, txn: IDBTransaction
}); });
log.set("countWithoutSession", countWithoutSession); log.set("countWithoutSession", countWithoutSession);
log.set("countWithSession", countWithSession); log.set("countWithSession", countWithSession);
inboundGroupSessions.createIndex("byBackup", "backup", {unique: false});
} }