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"
|
title: "oldone"
|
||||||
};
|
};
|
||||||
expect(await migrateItem(tag, 5.9, 6.0, "tag", db, "backup")).toBe(true);
|
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.noteIds).toBeUndefined();
|
||||||
expect(tag.alias).toBeUndefined();
|
expect(tag.alias).toBeUndefined();
|
||||||
expect(tag.title).toBe("oldone");
|
expect(tag.title).toBe("oldone");
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class Tags implements ICollection {
|
|||||||
async add(item: Partial<Tag>) {
|
async add(item: Partial<Tag>) {
|
||||||
item.title = item.title ? Tags.sanitize(item.title) : item.title;
|
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
|
const oldTag = item.id
|
||||||
? await this.tag(item.id)
|
? await this.tag(item.id)
|
||||||
: item.title
|
: item.title
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ const migrations: Migration[] = [
|
|||||||
// there's a case where dateCreated is null in tags
|
// there's a case where dateCreated is null in tags
|
||||||
item.dateCreated = item.dateCreated || Date.now();
|
item.dateCreated = item.dateCreated || Date.now();
|
||||||
item.title = alias || item.title;
|
item.title = alias || item.title;
|
||||||
item.id = getId(item.dateCreated);
|
item.id = makeId(item.title);
|
||||||
|
|
||||||
delete item.localOnly;
|
delete item.localOnly;
|
||||||
delete item.noteIds;
|
delete item.noteIds;
|
||||||
@@ -257,6 +257,9 @@ const migrations: Migration[] = [
|
|||||||
const newTagId =
|
const newTagId =
|
||||||
newTag?.id ||
|
newTag?.id ||
|
||||||
(await db.tags.add({
|
(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,
|
dateCreated: oldTag?.dateCreated,
|
||||||
dateModified: oldTag?.dateModified,
|
dateModified: oldTag?.dateModified,
|
||||||
title: alias || tag,
|
title: alias || tag,
|
||||||
@@ -278,6 +281,9 @@ const migrations: Migration[] = [
|
|||||||
const newColorId =
|
const newColorId =
|
||||||
newColor?.id ||
|
newColor?.id ||
|
||||||
(await db.colors.add({
|
(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,
|
dateCreated: oldColor?.dateCreated,
|
||||||
dateModified: oldColor?.dateModified,
|
dateModified: oldColor?.dateModified,
|
||||||
title: alias || item.color,
|
title: alias || item.color,
|
||||||
|
|||||||
Reference in New Issue
Block a user