fix: undefined allDb in firefox (#3417)
This commit is contained in:
@@ -78,47 +78,48 @@ export async function tryMigrate(
|
|||||||
}
|
}
|
||||||
// run the migration
|
// run the migration
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
allDb.map(meta => {
|
allDb &&
|
||||||
if (meta.name && meta.version === 1) {
|
allDb.map(meta => {
|
||||||
const name = meta.name;
|
if (meta.name && meta.version === 1) {
|
||||||
const version = meta.version;
|
const name = meta.name;
|
||||||
return openDB<IDBPDatabase<OldYjsDB>>(name, version).then(
|
const version = meta.version;
|
||||||
async oldDB => {
|
return openDB<IDBPDatabase<OldYjsDB>>(name, version).then(
|
||||||
if (!oldDB.objectStoreNames.contains('updates')) {
|
async oldDB => {
|
||||||
return;
|
if (!oldDB.objectStoreNames.contains('updates')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const t = oldDB
|
||||||
|
.transaction('updates', 'readonly')
|
||||||
|
.objectStore('updates');
|
||||||
|
const updates = await t.getAll();
|
||||||
|
if (
|
||||||
|
!Array.isArray(updates) ||
|
||||||
|
!updates.every(update => update instanceof Uint8Array)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const update = mergeUpdates(updates);
|
||||||
|
const workspaceTransaction = db
|
||||||
|
.transaction('workspace', 'readwrite')
|
||||||
|
.objectStore('workspace');
|
||||||
|
const data = await workspaceTransaction.get(name);
|
||||||
|
if (!data) {
|
||||||
|
console.log('upgrading the database');
|
||||||
|
await workspaceTransaction.put({
|
||||||
|
id: name,
|
||||||
|
updates: [
|
||||||
|
{
|
||||||
|
timestamp: Date.now(),
|
||||||
|
update,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const t = oldDB
|
);
|
||||||
.transaction('updates', 'readonly')
|
}
|
||||||
.objectStore('updates');
|
return void 0;
|
||||||
const updates = await t.getAll();
|
})
|
||||||
if (
|
|
||||||
!Array.isArray(updates) ||
|
|
||||||
!updates.every(update => update instanceof Uint8Array)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const update = mergeUpdates(updates);
|
|
||||||
const workspaceTransaction = db
|
|
||||||
.transaction('workspace', 'readwrite')
|
|
||||||
.objectStore('workspace');
|
|
||||||
const data = await workspaceTransaction.get(name);
|
|
||||||
if (!data) {
|
|
||||||
console.log('upgrading the database');
|
|
||||||
await workspaceTransaction.put({
|
|
||||||
id: name,
|
|
||||||
updates: [
|
|
||||||
{
|
|
||||||
timestamp: Date.now(),
|
|
||||||
update,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return void 0;
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
localStorage.setItem(`${dbName}-migration`, 'true');
|
localStorage.setItem(`${dbName}-migration`, 'true');
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user