refactor: migrate in serial

This commit is contained in:
thecodrr
2021-07-06 12:13:35 +05:00
parent 3709a63aae
commit d3b106094e

View File

@@ -3,9 +3,8 @@ 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 (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);
@@ -19,6 +18,7 @@ class Migrator {
}
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);
@@ -26,8 +26,7 @@ class Migrator {
await collection.dbCollection.add(item);
}
}
})
);
}
return true;
}
}