only reinsert all sessions if necessary
The purpose of this is data safety. If there ever was a broken model that corrupted data previously it would have ruined everything if it coincided with a schema migration. Now this is much less likely.
This commit is contained in:
parent
53e3b2539a
commit
b5ead20f0b
@ -142,12 +142,17 @@ export default class WbDb extends EventTarget {
|
||||
target: { result: db, transaction: trans },
|
||||
} = event;
|
||||
|
||||
let reinsertAll = false;
|
||||
|
||||
if (old < 1 && now >= 1)
|
||||
this.#version1(db, trans);
|
||||
if (old < 2 && now >= 2)
|
||||
if (old < 2 && now >= 2) {
|
||||
this.#version2(db, trans);
|
||||
reinsertAll = true;
|
||||
}
|
||||
|
||||
// update existing data to be visible in indexes
|
||||
if (reinsertAll)
|
||||
SessionRepo.reinsertAll(trans);
|
||||
}
|
||||
|
||||
|
||||
@ -133,8 +133,11 @@ export default function() {
|
||||
assert.true(second.failed, "second instance failed");
|
||||
});
|
||||
|
||||
QUnit.test("sessions are reinserted after upgrade", async function(assert) {
|
||||
let first = WbDb.get(true, 1);
|
||||
QUnit.test.each(
|
||||
"sessions are reinserted after upgrade",
|
||||
[{ before: 1, after: 2, reinsert: true }],
|
||||
async function(assert, input) {
|
||||
let first = WbDb.get(true, input.before);
|
||||
await waitForChange(first);
|
||||
first
|
||||
.db
|
||||
@ -149,9 +152,8 @@ export default function() {
|
||||
});
|
||||
first.db.close();
|
||||
|
||||
inst = WbDb.get(true, 2);
|
||||
inst = WbDb.get(true, input.after);
|
||||
await waitForChange();
|
||||
|
||||
let sessions = (await new Promise(function (resolve) {
|
||||
inst
|
||||
.db
|
||||
@ -161,7 +163,11 @@ export default function() {
|
||||
.getAll()
|
||||
.onsuccess = resolve;
|
||||
})).target.result;
|
||||
assert.strictEqual(sessions.length, 1, "session found by update index");
|
||||
|
||||
if (input.reinsert)
|
||||
assert.strictEqual(sessions.length, 1, "session found via index");
|
||||
else
|
||||
assert.strictEqual(sessions.length, 0, "session not in index");
|
||||
|
||||
// Note that the inserted session data is older than the `updated` field
|
||||
// in the model class. Thus it being present in the index proves that
|
||||
@ -170,7 +176,8 @@ export default function() {
|
||||
// Also note that the exact parsing and default value adding is already
|
||||
// checked in the model tests, thus it would be a duplicate to test that
|
||||
// here too.
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("schema version 1", async function(assert) {
|
||||
inst = WbDb.get(true, 1);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user