mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +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 v0Backup from "./__fixtures__/backup.v0.json";
|
||||||
import v2Backup from "./__fixtures__/backup.v2.json";
|
import v2Backup from "./__fixtures__/backup.v2.json";
|
||||||
import v3Backup from "./__fixtures__/backup.v3.json";
|
import v3Backup from "./__fixtures__/backup.v3.json";
|
||||||
|
import v4Backup from "./__fixtures__/backup.v4.json";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
StorageInterface.clear();
|
StorageInterface.clear();
|
||||||
@@ -70,6 +71,7 @@ describe.each([
|
|||||||
["v0", v0Backup],
|
["v0", v0Backup],
|
||||||
["v2", v2Backup],
|
["v2", v2Backup],
|
||||||
["v3", v3Backup],
|
["v3", v3Backup],
|
||||||
|
["v4", v4Backup],
|
||||||
])("testing backup version: %s", (version, data) => {
|
])("testing backup version: %s", (version, data) => {
|
||||||
test(`import ${version} backup`, () => {
|
test(`import ${version} backup`, () => {
|
||||||
return databaseTest().then(async (db) => {
|
return databaseTest().then(async (db) => {
|
||||||
@@ -78,14 +80,17 @@ describe.each([
|
|||||||
expect(db.settings.raw.id).toBeDefined();
|
expect(db.settings.raw.id).toBeDefined();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
db.notes.all.every(
|
db.notes.all.every((v) => {
|
||||||
(v) =>
|
return (
|
||||||
v.contentId &&
|
v.contentId &&
|
||||||
!v.content &&
|
!v.content &&
|
||||||
!v.notebook &&
|
!v.notebook &&
|
||||||
(!v.notebooks || Array.isArray(v.notebooks)) &&
|
(!v.notebooks ||
|
||||||
|
(Array.isArray(v.notebooks) &&
|
||||||
|
v.notebooks.every((nb) => !!nb.id))) &&
|
||||||
!v.colors
|
!v.colors
|
||||||
)
|
);
|
||||||
|
})
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ export const CHECK_IDS = {
|
|||||||
backupEncrypt: "backup:encrypt",
|
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) {
|
switch (version) {
|
||||||
case CURRENT_DATABASE_VERSION:
|
case CURRENT_DATABASE_VERSION:
|
||||||
case 3:
|
case 3:
|
||||||
|
case 4:
|
||||||
case 2: {
|
case 2: {
|
||||||
return backup;
|
return backup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,14 +49,22 @@ export const migrations = {
|
|||||||
if (item.colors && item.colors.length > 0) item.color = item.colors.pop();
|
if (item.colors && item.colors.length > 0) item.color = item.colors.pop();
|
||||||
delete item.colors;
|
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.dateEdited = Date.now();
|
||||||
item.migrated = true;
|
item.migrated = true;
|
||||||
return item;
|
return item;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
4: {
|
4.1: {
|
||||||
note: false,
|
note: false,
|
||||||
notebooks: false,
|
notebook: false,
|
||||||
tag: false,
|
tag: false,
|
||||||
trash: false,
|
trash: false,
|
||||||
delta: false,
|
delta: false,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "notes-core",
|
"name": "notes-core",
|
||||||
"version": "4.0.0",
|
"version": "4.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "./api/index.js",
|
"main": "./api/index.js",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user