trilium/db/migrations/0172__migrate_saved_search_notes.js

24 lines
687 B
JavaScript
Raw Normal View History

2020-12-01 06:20:12 +08:00
const repository = require('../../src/services/repository');
module.exports = () => {
for (const note of repository.getEntities("SELECT * FROM notes WHERE type = 'search' AND isProtected = 0 AND isDeleted = 0")) {
try {
let origContent = note.getJsonContent();
if (!origContent) {
continue;
}
note.addLabel('searchString', origContent.searchString);
note.setContent('');
note.mime = 'text/plain';
note.save();
}
catch (e) {
console.log(`Changing note content for note ${note.noteId} failed with: ${e.message} ${e.stack}`);
}
}
};