Skip to content

Build your personal knowledge base with Trilium Notes

notes are now soft-deleted

azivner3009c5e15eb1
diff --git a/migrations/0003__add_is_deleted_to_note.sql b/migrations/0003__add_is_deleted_to_note.sql
new file mode 100644
index 0000000000..8ba0afa7dc
--- /dev/null
+++ b/migrations/0003__add_is_deleted_to_note.sql
@@ -0,0 +1 @@
+ALTER TABLE notes ADD COLUMN is_deleted INTEGER NOT NULL DEFAULT 0
\ No newline at end of file
diff --git a/routes/api/notes.js b/routes/api/notes.js
index f3b6ef80be..dcd828c095 100644
--- a/routes/api/notes.js
+++ b/routes/api/notes.js
@@ -104,22 +104,24 @@ router.put('/: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();
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]);
for (const child of children) {
await deleteNote(child['note_id']);
}
- await sql.delete("notes_tree", noteId);
- await sql.delete("notes", noteId);
+ await sql.remove("notes_tree", noteId);
+ await sql.execute("update notes set is_deleted = 1 where note_id = ?", [noteId]);
await sql.addAudit(audit_category.DELETE_NOTE, req, noteId);
}
diff --git a/routes/api/tree.js b/routes/api/tree.js
index 5e5508663e..ddcaa17af0 100644
--- a/routes/api/tree.js
+++ b/routes/api/tree.js
@@ -19,6 +19,7 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => {
+ "from notes_tree "
+ "join notes on notes.note_id = notes_tree.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");
const root_notes = [];
diff --git a/services/migration.js b/services/migration.js
index 7b4c5ffb82..986d5313a1 100644
--- a/services/migration.js
+++ b/services/migration.js
@@ -2,7 +2,7 @@ const backup = require('./backup');
const sql = require('./sql');
const fs = require('fs-extra');
-const APP_DB_VERSION = 2;
+const APP_DB_VERSION = 3;
const MIGRATIONS_DIR = "./migrations";
async function migrate() {
diff --git a/views/migration.ejs b/views/migration.ejs
index 3c631e7078..8fa5075eb7 100644
--- a/views/migration.ejs
+++ b/views/migration.ejs
@@ -6,41 +6,45 @@
</head>
<body>
<div style="width: 800px; margin: auto;">
- <h1>Migration</h1>
-
- <div id="up-to-date" style="display:none;">
- <p>Your database is up-to-date with the application.</p>
- </div>
-
- <div id="need-to-migrate" style="display:none;">
- <p>Your database needs to be migrated to new version before you can use the application again.
- Database will be backed up before migration in case of something going wrong.</p>
-
- <table class="table table-bordered" style="width: 200px;">
- <tr>
- <th>Application version:</th>
- <td id="app-db-version" style="text-align: right;"></td>
- <tr>
- <th>Database version:</th>
- <td id="db-version" style="text-align: right;"></td>
- </tr>
- </table>
-
- <button class="btn btn-warning" id="run-migration">Run migration</button>
- </div>
-
- <div id="migration-result" style="display:none;">
- <h2>Migration result</h2>
-
- <table id="migration-table" class="table">
- <tr>
- <th>Database version</th>
- <th>Name</th>
- <th>Success</th>
- <th>Error</th>
- </tr>
- </table>
- </div>
+ <h1>Migration</h1>
+
+ <div id="up-to-date" style="display:none;">
+ <p>Your database is up-to-date with the application.</p>
+
+ <a href="/" class="btn btn-success">Continue to app</a>
+ </div>
+
+ <div id="need-to-migrate" style="display:none;">
+ <p>Your database needs to be migrated to new version before you can use the application again.
+ Database will be backed up before migration in case of something going wrong.</p>
+
+ <table class="table table-bordered" style="width: 200px;">
+ <tr>
+ <th>Application version:</th>
+ <td id="app-db-version" style="text-align: right;"></td>
+ <tr>
+ <th>Database version:</th>
+ <td id="db-version" style="text-align: right;"></td>
+ </tr>
+ </table>
+
+ <button class="btn btn-warning" id="run-migration">Run migration</button>
+ </div>
+
+ <div id="migration-result" style="display:none;">
+ <h2>Migration result</h2>
+
+ <table id="migration-table" class="table">
+ <tr>
+ <th>Database version</th>
+ <th>Name</th>
+ <th>Success</th>
+ <th>Error</th>
+ </tr>
+ </table>
+
+ <a href="/" class="btn btn-success">Continue to app</a>
+ </div>
</div>
<script type="text/javascript">