Skip to content

Commit

Permalink
Repro and resolve issue 1418 (#1419)
Browse files Browse the repository at this point in the history
* Repro of issue #1418

* Resolves #1418

* Opting out the new test when addons are active
or where we have a workaround for buggy browser to not delete stores
  • Loading branch information
dfahlander committed Oct 27, 2021
1 parent c0875ef commit de10544
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/classes/version/schema-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,8 @@ export function createMissingTables(newSchema: DbSchema, idbtrans: IDBTransactio
}

export function deleteRemovedTables(newSchema: DbSchema, idbtrans: IDBTransaction) {
for (var i = 0; i < idbtrans.db.objectStoreNames.length; ++i) {
var storeName = idbtrans.db.objectStoreNames[i];
if (newSchema[storeName] == null) {
idbtrans.db.deleteObjectStore(storeName);
}
}
[].slice.call(idbtrans.db.objectStoreNames).forEach(storeName =>
newSchema[storeName] == null && idbtrans.db.deleteObjectStore(storeName));
}

export function addIndex(store: IDBObjectStore, idx: IndexSpec) {
Expand Down
44 changes: 43 additions & 1 deletion test/tests-upgrading.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ test("upgrade", (assert) => {
db.version(6).stores({ store1: "++id,*email" });
db.version(7).stores({ store2: "uuid" });
// Deleting a version.
db.version(8).stores({ store1: null });
db.version(8).stores({store1: null });
return db.open().then(() => {
ok(true, "Could upgrade to version 8 - deleting an object store");
checkVersion(8);
Expand Down Expand Up @@ -826,3 +826,45 @@ promisedTest(
}
}
);


promisedTest(
"Issue 1418 - Not deleting all object stores",
async () => {
if (!supports("deleteObjectStoreAfterRead")) {
ok(true, "Skipping this test - buggy browser.");
return;
}
if (Dexie.addons.length > 0) {
ok(true, "Skipping this test - default addons are acitve and can add more object stores");
return;
}
const DBNAME = "issue1418";
await Dexie.delete(DBNAME);
let db = new Dexie(DBNAME);
db.version(1).stores({
a: '++',
b: '++',
c: '++',
d: '++',
e: '++'
});
await db.open();
equal(db.idbdb.objectStoreNames.length, 5, "There are 5 object stores");
db.close();

db = new Dexie(DBNAME);
db.version(2).stores({
a: null,
b: null,
c: null,
d: null,
e: '++'
});
await db.open();
equal(db.idbdb.objectStoreNames.length, 1, "There is only one object store now");
db.close();
await Dexie.delete(DBNAME);
}
);

0 comments on commit de10544

Please sign in to comment.