mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
feat: add dateEdited to dateModified migration
This commit is contained in:
@@ -72,6 +72,8 @@ describe.each([["v5.2", v52Backup]])(
|
|||||||
await db.backup.import(JSON.stringify(data));
|
await db.backup.import(JSON.stringify(data));
|
||||||
|
|
||||||
expect(db.settings.raw.id).toBeDefined();
|
expect(db.settings.raw.id).toBeDefined();
|
||||||
|
expect(db.settings.raw.dateModified).toBeDefined();
|
||||||
|
expect(db.settings.raw.dateEdited).toBeUndefined();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
db.notes.all.every((v) => {
|
db.notes.all.every((v) => {
|
||||||
@@ -80,21 +82,31 @@ describe.each([["v5.2", v52Backup]])(
|
|||||||
const hasTopicsInAllNotebooks =
|
const hasTopicsInAllNotebooks =
|
||||||
!v.notebooks ||
|
!v.notebooks ||
|
||||||
v.notebooks.every((nb) => !!nb.id && !!nb.topics && !nb.topic);
|
v.notebooks.every((nb) => !!nb.id && !!nb.topics && !nb.topic);
|
||||||
|
const hasDateModified = v.dateModified > 0;
|
||||||
return (
|
return (
|
||||||
doesNotHaveContent &&
|
doesNotHaveContent &&
|
||||||
!v.notebook &&
|
!v.notebook &&
|
||||||
hasTopicsInAllNotebooks &&
|
hasTopicsInAllNotebooks &&
|
||||||
doesNotHaveColors
|
doesNotHaveColors &&
|
||||||
|
hasDateModified
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
|
||||||
expect(db.notebooks.all.every((v) => v.title != null)).toBeTruthy();
|
expect(
|
||||||
|
db.notebooks.all.every((v) => v.title != null && v.dateModified > 0)
|
||||||
|
).toBeTruthy();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
db.attachments.all.every((v) => v.dateModified > 0 && !v.dateEdited)
|
||||||
|
).toBeTruthy();
|
||||||
|
|
||||||
const allContent = await db.content.all();
|
const allContent = await db.content.all();
|
||||||
expect(
|
expect(
|
||||||
allContent.every((v) => v.type === "tiny" || v.deleted)
|
allContent.every((v) => v.type === "tiny" || v.deleted)
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
expect(allContent.every((v) => !v.persistDateEdited)).toBeTruthy();
|
||||||
|
expect(allContent.every((v) => v.dateModified > 0)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -105,6 +117,7 @@ describe.each([["v5.2", v52Backup]])(
|
|||||||
verifyIndex(data, db, "notes", "notes");
|
verifyIndex(data, db, "notes", "notes");
|
||||||
verifyIndex(data, db, "notebooks", "notebooks");
|
verifyIndex(data, db, "notebooks", "notebooks");
|
||||||
verifyIndex(data, db, "content", "content");
|
verifyIndex(data, db, "content", "content");
|
||||||
|
verifyIndex(data, db, "attachments", "attachments");
|
||||||
// verifyIndex(data, db, "trash", "trash");
|
// verifyIndex(data, db, "trash", "trash");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export const EVENTS = {
|
|||||||
mediaAttachmentDownloaded: "attachments:mediaDownloaded",
|
mediaAttachmentDownloaded: "attachments:mediaDownloaded",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CURRENT_DATABASE_VERSION = 5.2;
|
export const CURRENT_DATABASE_VERSION = 5.3;
|
||||||
|
|
||||||
export function setUserPersonalizationBytes(userSalt) {
|
export function setUserPersonalizationBytes(userSalt) {
|
||||||
USER_PERSONALIZATION_HASH = new Uint8Array(
|
USER_PERSONALIZATION_HASH = new Uint8Array(
|
||||||
|
|||||||
@@ -92,12 +92,9 @@ export default class Backup {
|
|||||||
|
|
||||||
switch (version) {
|
switch (version) {
|
||||||
case CURRENT_DATABASE_VERSION:
|
case CURRENT_DATABASE_VERSION:
|
||||||
case 5.0:
|
|
||||||
case 5.1:
|
case 5.1:
|
||||||
case 4:
|
case 5.2:
|
||||||
case 4.1:
|
case 5.0: {
|
||||||
case 4.2:
|
|
||||||
case 4.3: {
|
|
||||||
return backup;
|
return backup;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,32 +1,16 @@
|
|||||||
export const migrations = {
|
export const migrations = {
|
||||||
4: {
|
|
||||||
note: function (item) {
|
|
||||||
if (item.notebooks && item.notebooks.every((n) => !n.id)) {
|
|
||||||
item.notebooks = undefined;
|
|
||||||
}
|
|
||||||
return migrations["4.1"].note(item);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
4.1: {
|
|
||||||
note: function (item) {
|
|
||||||
return migrations["4.2"].note(item);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
4.2: {
|
|
||||||
note: function (item) {
|
|
||||||
if (item.notebooks) {
|
|
||||||
item.notebooks = item.notebooks.map((nb) => {
|
|
||||||
return { id: nb.id, topics: nb.topics || [nb.topic] };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
item.migrated = true;
|
|
||||||
return item;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
4.3: {},
|
|
||||||
5.0: {},
|
5.0: {},
|
||||||
5.1: {},
|
5.1: {},
|
||||||
5.2: {
|
5.2: {
|
||||||
|
note: replaceDateEditedWithDateModified(),
|
||||||
|
notebook: replaceDateEditedWithDateModified(),
|
||||||
|
tag: replaceDateEditedWithDateModified(true),
|
||||||
|
attachment: replaceDateEditedWithDateModified(true),
|
||||||
|
trash: replaceDateEditedWithDateModified(),
|
||||||
|
tiny: replaceDateEditedWithDateModified(),
|
||||||
|
settings: replaceDateEditedWithDateModified(true),
|
||||||
|
},
|
||||||
|
5.3: {
|
||||||
note: false,
|
note: false,
|
||||||
notebook: false,
|
notebook: false,
|
||||||
tag: false,
|
tag: false,
|
||||||
@@ -36,3 +20,12 @@ export const migrations = {
|
|||||||
settings: false,
|
settings: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function replaceDateEditedWithDateModified(removeDateEditedProperty = false) {
|
||||||
|
return function (item) {
|
||||||
|
item.dateModified = item.dateEdited;
|
||||||
|
if (removeDateEditedProperty) delete item.dateEdited;
|
||||||
|
delete item.persistDateEdited;
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "notes-core",
|
"name": "notes-core",
|
||||||
"version": "6.15.0",
|
"version": "6.16.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "./api/index.js",
|
"main": "./api/index.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user