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

View File

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

View File

@@ -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;
} }

View File

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

View File

@@ -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": {