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 { 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;
} }
} }