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,31 +3,30 @@ 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);
|
if (!item) {
|
||||||
if (!item) {
|
continue;
|
||||||
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 (!!collection.dbCollection.merge) {
|
|
||||||
await collection.dbCollection.merge(item);
|
|
||||||
} else {
|
|
||||||
await collection.dbCollection.add(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user