mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 06:29:29 +01:00
refactor: migrate in serial
This commit is contained in:
@@ -3,9 +3,8 @@ import { migrations } from "../migrations";
|
|||||||
|
|
||||||
class Migrator {
|
class Migrator {
|
||||||
async migrate(collections, get, version) {
|
async migrate(collections, get, version) {
|
||||||
await Promise.all(
|
for (let collection of collections) {
|
||||||
collections.map(async (collection) => {
|
if (!collection.index || !collection.dbCollection) continue;
|
||||||
if (!collection.index || !collection.dbCollection) return;
|
|
||||||
for (var i = 0; i < collection.index.length; ++i) {
|
for (var i = 0; i < collection.index.length; ++i) {
|
||||||
let id = collection.index[i];
|
let id = collection.index[i];
|
||||||
let item = get(id);
|
let item = get(id);
|
||||||
@@ -19,6 +18,7 @@ class Migrator {
|
|||||||
}
|
}
|
||||||
const migrate = migrations[version][item.type || collection.type];
|
const migrate = migrations[version][item.type || collection.type];
|
||||||
if (migrate) item = migrate(item);
|
if (migrate) item = migrate(item);
|
||||||
|
item.migrated = true;
|
||||||
|
|
||||||
if (!!collection.dbCollection.merge) {
|
if (!!collection.dbCollection.merge) {
|
||||||
await collection.dbCollection.merge(item);
|
await collection.dbCollection.merge(item);
|
||||||
@@ -26,8 +26,7 @@ class Migrator {
|
|||||||
await collection.dbCollection.add(item);
|
await collection.dbCollection.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user