mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
fix: add minor migration
This commit is contained in:
1
packages/core/__tests__/__fixtures__/backup.v4.json
Normal file
1
packages/core/__tests__/__fixtures__/backup.v4.json
Normal file
File diff suppressed because one or more lines are too long
@@ -7,6 +7,7 @@ import {
|
||||
import v0Backup from "./__fixtures__/backup.v0.json";
|
||||
import v2Backup from "./__fixtures__/backup.v2.json";
|
||||
import v3Backup from "./__fixtures__/backup.v3.json";
|
||||
import v4Backup from "./__fixtures__/backup.v4.json";
|
||||
|
||||
beforeEach(() => {
|
||||
StorageInterface.clear();
|
||||
@@ -70,6 +71,7 @@ describe.each([
|
||||
["v0", v0Backup],
|
||||
["v2", v2Backup],
|
||||
["v3", v3Backup],
|
||||
["v4", v4Backup],
|
||||
])("testing backup version: %s", (version, data) => {
|
||||
test(`import ${version} backup`, () => {
|
||||
return databaseTest().then(async (db) => {
|
||||
@@ -78,14 +80,17 @@ describe.each([
|
||||
expect(db.settings.raw.id).toBeDefined();
|
||||
|
||||
expect(
|
||||
db.notes.all.every(
|
||||
(v) =>
|
||||
db.notes.all.every((v) => {
|
||||
return (
|
||||
v.contentId &&
|
||||
!v.content &&
|
||||
!v.notebook &&
|
||||
(!v.notebooks || Array.isArray(v.notebooks)) &&
|
||||
(!v.notebooks ||
|
||||
(Array.isArray(v.notebooks) &&
|
||||
v.notebooks.every((nb) => !!nb.id))) &&
|
||||
!v.colors
|
||||
)
|
||||
);
|
||||
})
|
||||
).toBeTruthy();
|
||||
|
||||
expect(
|
||||
|
||||
@@ -17,4 +17,4 @@ export const CHECK_IDS = {
|
||||
backupEncrypt: "backup:encrypt",
|
||||
};
|
||||
|
||||
export const CURRENT_DATABASE_VERSION = 4;
|
||||
export const CURRENT_DATABASE_VERSION = 4.1;
|
||||
|
||||
@@ -95,6 +95,7 @@ export default class Backup {
|
||||
switch (version) {
|
||||
case CURRENT_DATABASE_VERSION:
|
||||
case 3:
|
||||
case 4:
|
||||
case 2: {
|
||||
return backup;
|
||||
}
|
||||
|
||||
@@ -49,14 +49,22 @@ export const migrations = {
|
||||
if (item.colors && item.colors.length > 0) item.color = item.colors.pop();
|
||||
delete item.colors;
|
||||
|
||||
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;
|
||||
},
|
||||
},
|
||||
4: {
|
||||
4.1: {
|
||||
note: false,
|
||||
notebooks: false,
|
||||
notebook: false,
|
||||
tag: false,
|
||||
trash: false,
|
||||
delta: false,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "notes-core",
|
||||
"version": "4.0.0",
|
||||
"version": "4.1.0",
|
||||
"private": true,
|
||||
"main": "./api/index.js",
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user