mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
core: fix duplicate tags created during migration
This commit is contained in:
@@ -326,7 +326,8 @@ describe.concurrent("[5.9] make tags syncable", () => {
|
||||
title: "oldone"
|
||||
};
|
||||
expect(await migrateItem(tag, 5.9, 6.0, "tag", db, "backup")).toBe(true);
|
||||
expect(tag.id).not.toBe(makeId("oldone"));
|
||||
expect(tag.id).toBe(makeId("oldone"));
|
||||
expect(tag.dateCreated).toBeGreaterThan(0);
|
||||
expect(tag.noteIds).toBeUndefined();
|
||||
expect(tag.alias).toBeUndefined();
|
||||
expect(tag.title).toBe("oldone");
|
||||
|
||||
@@ -52,7 +52,7 @@ export class Tags implements ICollection {
|
||||
async add(item: Partial<Tag>) {
|
||||
item.title = item.title ? Tags.sanitize(item.title) : item.title;
|
||||
|
||||
const id = item.id || getId(item.dateCreated);
|
||||
const id = item.id || getId();
|
||||
const oldTag = item.id
|
||||
? await this.tag(item.id)
|
||||
: item.title
|
||||
|
||||
@@ -238,7 +238,7 @@ const migrations: Migration[] = [
|
||||
// there's a case where dateCreated is null in tags
|
||||
item.dateCreated = item.dateCreated || Date.now();
|
||||
item.title = alias || item.title;
|
||||
item.id = getId(item.dateCreated);
|
||||
item.id = makeId(item.title);
|
||||
|
||||
delete item.localOnly;
|
||||
delete item.noteIds;
|
||||
@@ -257,6 +257,9 @@ const migrations: Migration[] = [
|
||||
const newTagId =
|
||||
newTag?.id ||
|
||||
(await db.tags.add({
|
||||
// IMPORTANT: the id must be deterministic to avoid creating
|
||||
// duplicate colors when migrating on different devices
|
||||
id: makeId(alias || tag),
|
||||
dateCreated: oldTag?.dateCreated,
|
||||
dateModified: oldTag?.dateModified,
|
||||
title: alias || tag,
|
||||
@@ -278,6 +281,9 @@ const migrations: Migration[] = [
|
||||
const newColorId =
|
||||
newColor?.id ||
|
||||
(await db.colors.add({
|
||||
// IMPORTANT: the id must be deterministic to avoid creating
|
||||
// duplicate colors when migrating on different devices
|
||||
id: makeId(alias || item.color),
|
||||
dateCreated: oldColor?.dateCreated,
|
||||
dateModified: oldColor?.dateModified,
|
||||
title: alias || item.color,
|
||||
|
||||
Reference in New Issue
Block a user