fix: add minor migration

This commit is contained in:
thecodrr
2020-12-07 13:11:44 +05:00
parent 555ffd24f7
commit a7750dfc06
6 changed files with 23 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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(

View File

@@ -17,4 +17,4 @@ export const CHECK_IDS = {
backupEncrypt: "backup:encrypt",
};
export const CURRENT_DATABASE_VERSION = 4;
export const CURRENT_DATABASE_VERSION = 4.1;

View File

@@ -95,6 +95,7 @@ export default class Backup {
switch (version) {
case CURRENT_DATABASE_VERSION:
case 3:
case 4:
case 2: {
return backup;
}

View File

@@ -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,

View File

@@ -1,6 +1,6 @@
{
"name": "notes-core",
"version": "4.0.0",
"version": "4.1.0",
"private": true,
"main": "./api/index.js",
"devDependencies": {