Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

refactor: migrate in serial

thecodrrd3b106094e48
diff --git a/packages/core/database/migrator.js b/packages/core/database/migrator.js
index d739cdadf..e382182b7 100644
--- a/packages/core/database/migrator.js
+++ b/packages/core/database/migrator.js
@@ -3,31 +3,30 @@ import { migrations } from "../migrations";
class Migrator {
async migrate(collections, get, version) {
- await Promise.all(
- collections.map(async (collection) => {
- if (!collection.index || !collection.dbCollection) return;
- for (var i = 0; i < collection.index.length; ++i) {
- let id = collection.index[i];
- let item = get(id);
- if (!item) {
- continue;
- }
+ for (let collection of collections) {
+ if (!collection.index || !collection.dbCollection) continue;
+ for (var i = 0; i < collection.index.length; ++i) {
+ let id = collection.index[i];
+ let item = get(id);
+ if (!item) {
+ continue;
+ }
- if (item.deleted && !item.type) {
- await collection.dbCollection?._collection?.addItem(item);
- continue;
- }
- const migrate = migrations[version][item.type || collection.type];
- if (migrate) item = migrate(item);
+ if (item.deleted && !item.type) {
+ await collection.dbCollection?._collection?.addItem(item);
+ continue;
+ }
+ const migrate = migrations[version][item.type || collection.type];
+ if (migrate) item = migrate(item);
+ item.migrated = true;
- if (!!collection.dbCollection.merge) {
- await collection.dbCollection.merge(item);
- } else {
- await collection.dbCollection.add(item);
- }
+ if (!!collection.dbCollection.merge) {
+ await collection.dbCollection.merge(item);
+ } else {
+ await collection.dbCollection.add(item);
}
- })
- );
+ }
+ }
return true;
}
}