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 },
|
target: { result: db, transaction: trans },
|
||||||
} = event;
|
} = event;
|
||||||
|
|
||||||
|
let reinsertAll = false;
|
||||||
|
|
||||||
if (old < 1 && now >= 1)
|
if (old < 1 && now >= 1)
|
||||||
this.#version1(db, trans);
|
this.#version1(db, trans);
|
||||||
if (old < 2 && now >= 2)
|
if (old < 2 && now >= 2) {
|
||||||
this.#version2(db, trans);
|
this.#version2(db, trans);
|
||||||
|
reinsertAll = true;
|
||||||
|
}
|
||||||
|
|
||||||
// update existing data to be visible in indexes
|
// update existing data to be visible in indexes
|
||||||
|
if (reinsertAll)
|
||||||
SessionRepo.reinsertAll(trans);
|
SessionRepo.reinsertAll(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -133,8 +133,11 @@ export default function() {
|
|||||||
assert.true(second.failed, "second instance failed");
|
assert.true(second.failed, "second instance failed");
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("sessions are reinserted after upgrade", async function(assert) {
|
QUnit.test.each(
|
||||||
let first = WbDb.get(true, 1);
|
"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);
|
await waitForChange(first);
|
||||||
first
|
first
|
||||||
.db
|
.db
|
||||||
@ -149,9 +152,8 @@ export default function() {
|
|||||||
});
|
});
|
||||||
first.db.close();
|
first.db.close();
|
||||||
|
|
||||||
inst = WbDb.get(true, 2);
|
inst = WbDb.get(true, input.after);
|
||||||
await waitForChange();
|
await waitForChange();
|
||||||
|
|
||||||
let sessions = (await new Promise(function (resolve) {
|
let sessions = (await new Promise(function (resolve) {
|
||||||
inst
|
inst
|
||||||
.db
|
.db
|
||||||
@ -161,7 +163,11 @@ export default function() {
|
|||||||
.getAll()
|
.getAll()
|
||||||
.onsuccess = resolve;
|
.onsuccess = resolve;
|
||||||
})).target.result;
|
})).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
|
// 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
|
// 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
|
// 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
|
// checked in the model tests, thus it would be a duplicate to test that
|
||||||
// here too.
|
// here too.
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
QUnit.test("schema version 1", async function(assert) {
|
QUnit.test("schema version 1", async function(assert) {
|
||||||
inst = WbDb.get(true, 1);
|
inst = WbDb.get(true, 1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user