Skip to content

Commit

Permalink
Repro of Issue770 + cherry pick resolution of dexie#612 (dexie#773)
Browse files Browse the repository at this point in the history
Repro of dexie#770. Once I cherry picked the resolution of dexie#612, it also fixed dexie#770 as it does not wait for Promise.follow() to complete when upgrader returns a Promise.

This is in line with how db.transaction() works.
  • Loading branch information
dfahlander authored Nov 12, 2018
1 parent b7bbeaf commit a6d9471
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/classes/version/schema-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ export function runUpgraders(db: Dexie, oldVersion: number, idbUpgradeTrans: IDB
trans.create(idbUpgradeTrans);
trans._completion.catch(reject);
const rejectTransaction = trans._reject.bind(trans);
const transless = PSD.transless || PSD;
newScope(() => {
PSD.trans = trans;
PSD.transless = transless;
if (oldVersion === 0) {
// Create tables:
keys(globalSchema).forEach(tableName => {
Expand Down
45 changes: 44 additions & 1 deletion test/tests-misc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Dexie from 'dexie';
import {module, stop, start, asyncTest, equal, ok} from 'QUnit';
import {module, stop, start, asyncTest, equal, deepEqual, ok} from 'QUnit';
import {resetDatabase, spawnedTest, promisedTest} from './dexie-unittest-utils';

const async = Dexie.async;
Expand Down Expand Up @@ -86,6 +86,49 @@ asyncTest("Adding object with falsy keys", function () {
}).finally(start);
});

promisedTest("#770", async () => {
const dbName = 'TestDB-' + Math.random();
const db = new Dexie(dbName, {addons: []});
const runnedVersions = [];
try {
db.version(1).stores({ test: 'id' });
await db.test.put({ id: 1 });
await db.open();
db.close();
db = new Dexie(dbName);
db.version(1).stores({ test: 'id' });
db.version(2).stores({ test: 'id' }).upgrade(async t => {
runnedVersions.push(2);
const rowsToCopy = await t.test.toArray();
await Dexie.waitFor((async ()=>{
const otherDB = new Dexie(dbName + '-another-unrelated-db', {addons: []});
otherDB.version(1).stores({foo: 'id'});
await otherDB.open();
await otherDB.foo.bulkAdd(rowsToCopy);
otherDB.close();
})());
});
db.version(3).stores({ test: 'id' }).upgrade(t => {
runnedVersions.push(3);
});

await db.open();
deepEqual(runnedVersions, [2, 3], "Versions 3 did indeed proceed (as well as version 2)");
const otherDB = new Dexie(dbName + '-another-unrelated-db', {addons: []});
otherDB.version(1).stores({foo: 'id'});
const otherDbRows = await otherDB.foo.toArray();
const origDbRows = await db.test.toArray();
deepEqual(otherDbRows, origDbRows, "All rows was copied atomically");
db.close();
otherDB.close();
} catch (err) {
ok(false, "Error " + err);
} finally {
await db.delete();
await new Dexie(dbName + '-another-unrelated-db', {addons: []}).delete();
}
});

asyncTest("#102 Passing an empty array to anyOf throws exception", async(function* () {
try {
let count = yield db.users.where("username").anyOf([]).count();
Expand Down

0 comments on commit a6d9471

Please sign in to comment.