Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: undefined allDb in firefox (#3417)

fourdim57c27e6a4b51
diff --git a/packages/y-indexeddb/src/utils.ts b/packages/y-indexeddb/src/utils.ts
index 9258975145..0af92ffe03 100644
--- a/packages/y-indexeddb/src/utils.ts
+++ b/packages/y-indexeddb/src/utils.ts
@@ -78,47 +78,48 @@ export async function tryMigrate(
}
// run the migration
await Promise.all(
- allDb.map(meta => {
- if (meta.name && meta.version === 1) {
- const name = meta.name;
- const version = meta.version;
- return openDB<IDBPDatabase<OldYjsDB>>(name, version).then(
- async oldDB => {
- if (!oldDB.objectStoreNames.contains('updates')) {
- return;
+ allDb &&
+ allDb.map(meta => {
+ if (meta.name && meta.version === 1) {
+ const name = meta.name;
+ const version = meta.version;
+ return openDB<IDBPDatabase<OldYjsDB>>(name, version).then(
+ async oldDB => {
+ 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');
- 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;
- })
+ );
+ }
+ return void 0;
+ })
);
localStorage.setItem(`${dbName}-migration`, 'true');
break;