From 2734e50a97a378e08bc8f4130c0fbf0b772ea11e Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Fri, 9 Feb 2024 10:41:00 +0500 Subject: [PATCH] core: fix migration bugs --- packages/core/src/api/lookup.ts | 2 +- packages/core/src/database/backup.ts | 3 +++ packages/core/src/migrations.ts | 13 ++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/core/src/api/lookup.ts b/packages/core/src/api/lookup.ts index 49f519827..cc2ee075f 100644 --- a/packages/core/src/api/lookup.ts +++ b/packages/core/src/api/lookup.ts @@ -43,7 +43,7 @@ export default class Lookup { return this.toSearchResults(async (limit) => { if (query.length <= 3) return []; - const db = this.db.sql() as Kysely; + const db = this.db.sql() as unknown as Kysely; query = query.replace(/"/, '""'); const result = await db .with("matching", (eb) => diff --git a/packages/core/src/database/backup.ts b/packages/core/src/database/backup.ts index e7f826627..0da1d2981 100644 --- a/packages/core/src/database/backup.ts +++ b/packages/core/src/database/backup.ts @@ -434,6 +434,9 @@ export default class Backup { } const collectionKey = itemTypeToCollectionKey[itemType]; + + if (!collectionKey) continue; + const collection = collectionKey === "sessioncontent" ? this.db.noteHistory.sessionContent.collection diff --git a/packages/core/src/migrations.ts b/packages/core/src/migrations.ts index 53a5b65be..53dd30e5d 100644 --- a/packages/core/src/migrations.ts +++ b/packages/core/src/migrations.ts @@ -181,6 +181,13 @@ const migrations: Migration[] = [ if (!item.deletedBy) item.deletedBy = "user"; return true; }, + color: async (item, db, migrationType) => { + return ( + (await migrations + .find((migration) => migration.version === 5.9) + ?.items.tag?.(item as any, db, migrationType)) || false + ); + }, tag: async (item, db) => { const oldTagId = makeId(item.title); const alias = db.legacySettings.getAlias(item.id); @@ -325,6 +332,7 @@ const migrations: Migration[] = [ } delete item.topics; delete item.totalNotes; + delete item.topic; return true; }, shortcut: (item) => { @@ -386,8 +394,10 @@ const migrations: Migration[] = [ }, tiptap: (item) => { item.locked = isCipher(item.data); + delete item.resolved; return true; }, + all: () => true }, async vaultKey(db, key) { @@ -444,7 +454,8 @@ export async function migrateItem( const result = await itemMigrator(item, database, migrationType); if (result === "skip") return "skip"; if (result) { - if (item.type && item.type !== type) type = item.type as TItemType; + if (item.type && item.type !== "trash" && item.type !== type) + type = item.type as TItemType; count++; } }