mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
core: add support for localOnly migrations
This commit is contained in:
@@ -476,7 +476,13 @@ async function deserializeItem(decryptedItem, version, database) {
|
||||
deserialized.synced = true;
|
||||
|
||||
if (!deserialized.alg && !deserialized.cipher) {
|
||||
await migrateItem(deserialized, version, deserialized.type, database);
|
||||
await migrateItem(
|
||||
deserialized,
|
||||
version,
|
||||
deserialized.type,
|
||||
database,
|
||||
"sync"
|
||||
);
|
||||
}
|
||||
return deserialized;
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ export default class Backup {
|
||||
// since items in trash can have their own set of migrations,
|
||||
// we have to run the migration again to account for that.
|
||||
if (item.type === "trash" && item.itemType)
|
||||
await migrateItem(item, version, item.itemType, this._db);
|
||||
await migrateItem(item, version, item.itemType, this._db, "backup");
|
||||
|
||||
const collectionKey = itemTypeToCollectionKey[item.itemType || item.type];
|
||||
if (collectionKey) {
|
||||
|
||||
@@ -78,7 +78,8 @@ class Migrator {
|
||||
item,
|
||||
version,
|
||||
item.type || collection.type || collection.dbCollection.type,
|
||||
db
|
||||
db,
|
||||
"local"
|
||||
);
|
||||
|
||||
if (migrated) {
|
||||
|
||||
@@ -136,16 +136,24 @@ const migrations = [
|
||||
{
|
||||
version: 5.8,
|
||||
items: {
|
||||
all: (item) => {
|
||||
delete item.remote;
|
||||
return true;
|
||||
all: (item, _db, migrationType) => {
|
||||
if (migrationType === "local") {
|
||||
delete item.remote;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ version: 5.9, items: {} }
|
||||
];
|
||||
|
||||
export async function migrateItem(item, version, type, database) {
|
||||
export async function migrateItem(
|
||||
item,
|
||||
version,
|
||||
type,
|
||||
database,
|
||||
migrationType
|
||||
) {
|
||||
let migrationStartIndex = migrations.findIndex((m) => m.version === version);
|
||||
if (migrationStartIndex <= -1) {
|
||||
throw new Error(
|
||||
@@ -164,7 +172,7 @@ export async function migrateItem(item, version, type, database) {
|
||||
? migration.items[type] || migration.items.all
|
||||
: null;
|
||||
if (!itemMigrator) continue;
|
||||
if (await itemMigrator(item, database)) count++;
|
||||
if (await itemMigrator(item, database, migrationType)) count++;
|
||||
}
|
||||
|
||||
return count > 0;
|
||||
|
||||
Reference in New Issue
Block a user