mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	added date_modified to notes_tree
This commit is contained in:
		
							
								
								
									
										4
									
								
								bin/www
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								bin/www
									
									
									
									
									
								
							| @@ -1,5 +1,9 @@ | ||||
| #!/usr/bin/env node | ||||
|  | ||||
| process.on('unhandledRejection', (reason, p) => { | ||||
|     // this makes sure that stacktrace of failed promise is printed out | ||||
|     console.log('Unhandled Rejection at: Promise', p, 'reason:', reason); | ||||
| }); | ||||
|  | ||||
| var app = require('../app'); | ||||
| var debug = require('debug')('node:server'); | ||||
|   | ||||
							
								
								
									
										1
									
								
								migrations/0004__add_date_modified_to_notes_tree.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								migrations/0004__add_date_modified_to_notes_tree.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| ALTER TABLE notes_tree ADD COLUMN date_modified INTEGER NOT NULL DEFAULT 0 | ||||
| @@ -153,7 +153,9 @@ router.post('/:parentNoteId/children', async (req, res, next) => { | ||||
|  | ||||
|         newNotePos = afterNote['note_pos'] + 1; | ||||
|  | ||||
|         await sql.execute('update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos > ?', [parentNoteId, afterNote['note_pos']]); | ||||
|         const now = utils.nowTimestamp(); | ||||
|  | ||||
|         await sql.execute('update notes_tree set note_pos = note_pos + 1, date_modified = ? where note_pid = ? and note_pos > ?', [now, parentNoteId, afterNote['note_pos']]); | ||||
|     } | ||||
|     else { | ||||
|         throw new ('Unknown target: ' + note['target']); | ||||
| @@ -179,7 +181,8 @@ router.post('/:parentNoteId/children', async (req, res, next) => { | ||||
|         'note_id': noteId, | ||||
|         'note_pid': parentNoteId, | ||||
|         'note_pos': newNotePos, | ||||
|         'is_expanded': 0 | ||||
|         'is_expanded': 0, | ||||
|         'date_modified': utils.nowTimestamp() | ||||
|     }); | ||||
|  | ||||
|     await sql.commit(); | ||||
|   | ||||
| @@ -20,9 +20,12 @@ router.put('/:noteId/moveTo/:parentId', auth.checkApiAuth, async (req, res, next | ||||
|     else | ||||
|         newNotePos = maxNotePos + 1; | ||||
|  | ||||
|     const now = utils.nowTimestamp(); | ||||
|  | ||||
|     await sql.beginTransaction(); | ||||
|  | ||||
|     await sql.execute("update notes_tree set note_pid = ?, note_pos = ? where note_id = ?", [parentId, newNotePos, noteId]); | ||||
|     await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?", | ||||
|         [parentId, newNotePos, now, noteId]); | ||||
|  | ||||
|     await sql.addAudit(audit_category.CHANGE_PARENT, req, noteId); | ||||
|  | ||||
| @@ -37,12 +40,15 @@ router.put('/:noteId/moveBefore/:beforeNoteId', async (req, res, next) => { | ||||
|  | ||||
|     const beforeNote = await sql.getSingleResult("select * from notes_tree where note_id = ?", [beforeNoteId]); | ||||
|  | ||||
|     if (beforeNote !== null) { | ||||
|     if (beforeNote) { | ||||
|         const now = utils.nowTimestamp(); | ||||
|  | ||||
|         await sql.beginTransaction(); | ||||
|  | ||||
|         await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_id = ?", [beforeNoteId]); | ||||
|         await sql.execute("update notes_tree set note_pos = note_pos + 1, date_modified = ? where note_id = ?", [now, beforeNoteId]); | ||||
|  | ||||
|         await sql.execute("update notes_tree set note_pid = ?, note_pos = ? where note_id = ?", [beforeNote['note_pid'], beforeNote['note_pos'], noteId]); | ||||
|         await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?", | ||||
|             [beforeNote['note_pid'], beforeNote['note_pos'], now, noteId]); | ||||
|  | ||||
|         await sql.addAudit(audit_category.CHANGE_POSITION, req, noteId); | ||||
|  | ||||
| @@ -58,12 +64,16 @@ router.put('/:noteId/moveAfter/:afterNoteId', async (req, res, next) => { | ||||
|  | ||||
|     const afterNote = await sql.getSingleResult("select * from notes_tree where note_id = ?", [afterNoteId]); | ||||
|  | ||||
|     if (afterNote !== null) { | ||||
|     if (afterNote) { | ||||
|         const now = utils.nowTimestamp(); | ||||
|  | ||||
|         await sql.beginTransaction(); | ||||
|  | ||||
|         await sql.execute("update notes_tree set note_pos = note_pos + 1 where note_pid = ? and note_pos > ?", [afterNote['note_pid'], afterNote['note_pos']]); | ||||
|         await sql.execute("update notes_tree set note_pos = note_pos + 1, date_modified = ? where note_pid = ? and note_pos > ?", | ||||
|             [now, afterNote['note_pid'], afterNote['note_pos']]); | ||||
|  | ||||
|         await sql.execute("update notes_tree set note_pid = ?, note_pos = ? where note_id = ?", [afterNote['note_pid'], afterNote['note_pos'] + 1, noteId]); | ||||
|         await sql.execute("update notes_tree set note_pid = ?, note_pos = ?, date_modified = ? where note_id = ?", | ||||
|             [afterNote['note_pid'], afterNote['note_pos'] + 1, now, noteId]); | ||||
|  | ||||
|         await sql.addAudit(audit_category.CHANGE_POSITION, req, noteId); | ||||
|  | ||||
| @@ -74,10 +84,11 @@ router.put('/:noteId/moveAfter/:afterNoteId', async (req, res, next) => { | ||||
| }); | ||||
|  | ||||
| router.put('/:noteId/expanded/:expanded', async (req, res, next) => { | ||||
|     let noteId = req.params.noteId; | ||||
|     let expanded = req.params.expanded; | ||||
|     const noteId = req.params.noteId; | ||||
|     const expanded = req.params.expanded; | ||||
|     const now = utils.nowTimestamp(); | ||||
|  | ||||
|     await sql.execute("update notes_tree set is_expanded = ? where note_id = ?", [expanded, noteId]); | ||||
|     await sql.execute("update notes_tree set is_expanded = ?, date_modified = ? where note_id = ?", [expanded, now, noteId]); | ||||
|  | ||||
|     // no audit here, not really important | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ const backup = require('./backup'); | ||||
| const sql = require('./sql'); | ||||
| const fs = require('fs-extra'); | ||||
|  | ||||
| const APP_DB_VERSION = 3; | ||||
| const APP_DB_VERSION = 4; | ||||
| const MIGRATIONS_DIR = "./migrations"; | ||||
|  | ||||
| async function migrate() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user