Files
notesnook/packages/core/migrations.js

75 lines
1.7 KiB
JavaScript
Raw Normal View History

export const migrations = {
0: {
note: function (item) {
2020-12-07 12:02:01 +05:00
// note.content -> note.contentId
2020-12-06 11:13:17 +05:00
if (item.content) {
const contentId = item.content.delta;
delete item.content;
item.contentId = contentId;
}
2020-12-07 12:02:01 +05:00
return migrations[2].note(item);
},
delta: function (item) {
item.data = item.data.ops;
item.type = "delta";
item.dateEdited = Date.now();
item.migrated = true;
return item;
},
trash: function (item) {
item.itemType = item.type;
item.type = "trash";
if (item.itemType === "note") {
item.contentId = item.content.delta;
delete item.content;
}
item.dateEdited = Date.now();
item.migrated = true;
return item;
},
},
2: {
note: function (item) {
2020-12-07 12:02:01 +05:00
// note.notebook -> note.notebooks
const notebook = item.notebook;
delete item.notebook;
if (notebook && notebook.id && notebook.topic) {
2020-12-08 11:58:45 +05:00
notebook.topics = [notebook.topic];
2020-12-07 12:02:01 +05:00
delete notebook.topic;
item.notebooks = [notebook];
}
return migrations[3].note(item);
},
},
3: {
note: function (item) {
// note.colors -> note.color
if (item.colors && item.colors.length > 0) item.color = item.colors.pop();
delete item.colors;
2020-12-07 13:11:44 +05:00
return migrations[4].note(item);
},
},
4: {
note: function (item) {
if (item.notebooks && item.notebooks.every((n) => !n.id)) {
item.notebooks = undefined;
}
item.dateEdited = Date.now();
item.migrated = true;
return item;
},
},
2020-12-07 15:24:08 +05:00
4.1: {},
4.2: {
note: false,
2020-12-07 13:11:44 +05:00
notebook: false,
tag: false,
trash: false,
2020-12-06 11:13:17 +05:00
delta: false,
settings: false,
},
};