mirror of
https://github.com/zadam/trilium.git
synced 2024-12-26 17:21:23 +08:00
notes are now soft-deleted
This commit is contained in:
parent
1cc75ad385
commit
3009c5e15e
5 changed files with 42 additions and 34 deletions
1
migrations/0003__add_is_deleted_to_note.sql
Normal file
1
migrations/0003__add_is_deleted_to_note.sql
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE notes ADD COLUMN is_deleted INTEGER NOT NULL DEFAULT 0
|
|
@ -104,22 +104,24 @@ router.put('/:noteId', async (req, res, next) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
router.delete('/:noteId', async (req, res, next) => {
|
router.delete('/:noteId', async (req, res, next) => {
|
||||||
await deleteNote(req.params.noteId);
|
await sql.beginTransaction();
|
||||||
|
|
||||||
|
await deleteNote(req.params.noteId, req);
|
||||||
|
|
||||||
await sql.commit();
|
await sql.commit();
|
||||||
|
|
||||||
res.send({});
|
res.send({});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function deleteNote(noteId) {
|
async function deleteNote(noteId, req) {
|
||||||
const children = await sql.getResults("select note_id from notes_tree where note_pid = ?", [noteId]);
|
const children = await sql.getResults("select note_id from notes_tree where note_pid = ?", [noteId]);
|
||||||
|
|
||||||
for (const child of children) {
|
for (const child of children) {
|
||||||
await deleteNote(child['note_id']);
|
await deleteNote(child['note_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
await sql.delete("notes_tree", noteId);
|
await sql.remove("notes_tree", noteId);
|
||||||
await sql.delete("notes", noteId);
|
await sql.execute("update notes set is_deleted = 1 where note_id = ?", [noteId]);
|
||||||
|
|
||||||
await sql.addAudit(audit_category.DELETE_NOTE, req, noteId);
|
await sql.addAudit(audit_category.DELETE_NOTE, req, noteId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => {
|
||||||
+ "from notes_tree "
|
+ "from notes_tree "
|
||||||
+ "join notes on notes.note_id = notes_tree.note_id "
|
+ "join notes on notes.note_id = notes_tree.note_id "
|
||||||
+ "left join notes as clone on notes.note_clone_id = clone.note_id "
|
+ "left join notes as clone on notes.note_clone_id = clone.note_id "
|
||||||
|
+ "where notes.is_deleted = 0 "
|
||||||
+ "order by note_pid, note_pos");
|
+ "order by note_pid, note_pos");
|
||||||
|
|
||||||
const root_notes = [];
|
const root_notes = [];
|
||||||
|
|
|
@ -2,7 +2,7 @@ const backup = require('./backup');
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
const APP_DB_VERSION = 2;
|
const APP_DB_VERSION = 3;
|
||||||
const MIGRATIONS_DIR = "./migrations";
|
const MIGRATIONS_DIR = "./migrations";
|
||||||
|
|
||||||
async function migrate() {
|
async function migrate() {
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
<div id="up-to-date" style="display:none;">
|
<div id="up-to-date" style="display:none;">
|
||||||
<p>Your database is up-to-date with the application.</p>
|
<p>Your database is up-to-date with the application.</p>
|
||||||
|
|
||||||
|
<a href="/" class="btn btn-success">Continue to app</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="need-to-migrate" style="display:none;">
|
<div id="need-to-migrate" style="display:none;">
|
||||||
|
@ -40,6 +42,8 @@
|
||||||
<th>Error</th>
|
<th>Error</th>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<a href="/" class="btn btn-success">Continue to app</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue