From cf8334607e569647ae8a3b8082cc1201969325a0 Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 23 Dec 2017 13:16:18 -0500 Subject: [PATCH] added demo document SQL scripts --- db/main_notes.sql | 57 +++++++++++++++++ db/main_notes_tree.sql | 52 ++++++++++++++++ schema.sql => db/schema.sql | 109 +++++++++++++++++---------------- export-schema.sh | 6 +- routes/api/cleanup.js | 7 ++- routes/api/sync.js | 5 ++ services/consistency_checks.js | 4 +- 7 files changed, 182 insertions(+), 58 deletions(-) create mode 100644 db/main_notes.sql create mode 100644 db/main_notes_tree.sql rename schema.sql => db/schema.sql (75%) diff --git a/db/main_notes.sql b/db/main_notes.sql new file mode 100644 index 000000000..9bc8a2028 --- /dev/null +++ b/db/main_notes.sql @@ -0,0 +1,57 @@ +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('root', 'root', 'root', 0, 0, '2017-12-22T11:41:07.000Z', '2017-12-22T11:41:07.000Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('1Heh2acXfPNt', 'Trilium Demo', '

Welcome to Trilium!

 

This is initial document provided by default Trilium to showcase some of its features and also give you some ideas how you might structure your notes. You can play with it, modify note content and tree structure as you wish.

 

If you need any help, visit Trilium wesite: https://github.com/zadam/trilium

 

Once you''re finished with experimenting and want to cleanup these pages, you can simply delete them all.

', 0, 0, '2017-12-23T00:46:39.304Z', '2017-12-23T04:08:45.445Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('3RkyK9LI18dO', 'Journal', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T01:20:04.181Z', '2017-12-23T18:07:55.377Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('L1Ox40M1aEyy', '2016', '

No content.

 

 

 

 

', 0, 0, '2017-12-23T01:20:45.365Z', '2017-12-23T16:40:43.129Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('HJusZTbBU494', '2017', '

No content.

', 0, 0, '2017-12-23T01:20:50.709Z', '2017-12-23T16:41:03.119Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('3oldoiMUPOlr', 'December', '', 0, 0, '2017-12-23T01:20:55.775Z', '2017-12-23T01:21:05.806Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('MG0wntwILQW6', '22 - friday', 'Daily summary', 0, 0, '2017-12-23T01:21:10.517Z', '2017-12-23T01:22:45.814Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('ZC78NlmdXeC6', 'Linux', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T01:22:55.255Z', '2017-12-23T18:08:10.381Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('NncfGH8dyNjJ', 'Programming', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T01:23:02.584Z', '2017-12-23T18:08:20.179Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('eouCLkjbruai', 'Java', '', 0, 0, '2017-12-23T01:23:28.291Z', '2017-12-23T01:23:31.944Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('C44aq4mkaX67', 'Bash scripting', '

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been distributed widely as the default login shell for most Linux distributions and Apple''s macOS (formerly OS X). A version is also available for Windows 10.

 

Bash on Wikipedia

', 0, 0, '2017-12-23T01:23:31.879Z', '2017-12-23T04:00:49.098Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('I6Cw88AirBBl', 'While loop', '

Documentation: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_02.html

 

#!/bin/bash + +

# This script opens 4 terminal windows. + +

 

i="0" + +

while [ $i -lt 4 ] +

do +

    xterm & +

    i=$[$i+1] +

done

', 0, 0, '2017-12-23T01:24:04.681Z', '2017-12-23T01:26:07.786Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('mcEwFMSjhlvL', 'Bash startup modes', '

Login shell

As a "login shell", Bash reads and sets (executes) the user''s profile from /etc/profile and one of ~/.bash_profile, ~/.bash_login, or ~/.profile (in that order, using the first one that''s readable!).

When a login shell exits, Bash reads and executes commands from the file ~/.bash_logout, if it exists.

Why an extra login shell mode? There are many actions and variable sets that only make sense for the initial user login. That''s why all UNIX® shells have (should have) a "login" mode.

Methods to start Bash as a login shell:

Methods to test for login shell mode:

Related switches:

Interactive shell

When Bash starts as an interactive non-login shell, it reads and executes commands from ~/.bashrc. This file should contain, for example, aliases, since they need to be defined in every shell as they''re not inherited from the parent shell.

The feature to have a system-wide /etc/bash.bashrc or a similar system-wide rc-file is specific to vendors and distributors that ship their own, patched variant of Bash. The classic way to have a system-wide rc file is to source /etc/bashrc from every user''s ~/.bashrc.

Methods to test for interactive-shell mode:

Related switches:

SH mode

When Bash starts in SH compatiblity mode, it tries to mimic the startup behaviour of historical versions of sh as closely as possible, while conforming to the POSIX® standard as well. The profile files read are /etc/profile and ~/.profile, if it''s a login shell.

If it''s not a login shell, the environment variable ENV is evaluated and the resulting filename is used as the name of the startup file.

After the startup files are read, Bash enters the POSIX(r) compatiblity mode (for running, not for starting!).

Bash starts in sh compatiblity mode when:

', 0, 0, '2017-12-23T01:29:35.974Z', '2017-12-23T01:34:10.493Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('CF2lUIJAr6Ey', 'Python', '', 0, 0, '2017-12-23T01:34:37.658Z', '2017-12-23T01:34:40.465Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('xkXwueRoDNeN', 'Christmas shopping', '

 

', 0, 0, '2017-12-23T01:35:40.306Z', '2017-12-23T16:43:08.157Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('eXHZAKsMYgur', 'Books', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T03:32:42.868Z', '2017-12-23T18:08:03.857Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('2WU27ekfy07E', 'To read', '

Checkout Kindle daily deals: https://www.amazon.com/gp/feature.html?docId=1000677541

 

', 0, 0, '2017-12-23T03:32:49.379Z', '2017-12-23T03:59:01.970Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('TjWEndYCCg7g', 'Reviews', '', 0, 0, '2017-12-23T03:33:23.584Z', '2017-12-23T03:33:35.089Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('8nRNDJGyGs2Z', 'The Mechanical', '

Amazon: https://www.amazon.com/Mechanical-Alchemy-Wars-Ian-Tregillis/dp/0316248002

Author: Ian Tregillis

Dates of reading: 24. 11. 2017 -13. 12. 2017

 

I enjoyed this book a lot. It''s slow moving at times with the author taking his time with conversations and descriptions of them. The premise is very interesting, but I''m sad that it wasn''t elaborated more deeply - e.g. the history and development of the clakker technology with Huygens and how Spinoza comes into the picture. Maybe the author saves it for the next two parts of the book.

 

Language can be intimidating at first for non-native english speakers - author uses wide range of vocabulary. Fortunately it gets better after a while as reader adjusts.

', 0, 0, '2017-12-23T03:33:37.327Z', '2017-12-23T03:36:51.534Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('9zSwD89vgzNO', 'Highlights', '

Like a raindrop rolling down dry valleys to the sea, his body sensed the contours of agony and helplessly followed their gradient. Impelled by alchemical compulsion rather than gravity, Jax became an unstoppable boulder careering along gullies of human whim.

 

Free Will was a vacuum, a negative space. It was the absence of coercion, the absence of compulsion, the absence of agony.

 

Overwhelming: he could do anything he wanted. But the grand sum of anything-at-all was nothing-at-all. The topology of freedom offered no gradients to nudge him, no landmarks to guide him. How did humans guide themselves? How did they know what to do and what not to do? How did they know when to do anything without the benefit of geasa and metageasa to prioritize every single action of their waking lives? How did they order their daily existence without somebody to tell them what to do?

Life as a slave was unspeakable; life as a slave who had briefly tasted freedom was unthinkable. Clakkers carried complex geasa by dint of alchemy; humans carried heavy obligations, too, but called them culture. Society.

', 0, 0, '2017-12-23T03:37:04.912Z', '2017-12-23T03:38:16.533Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('u5t1EvWa3CMO', 'Man''s search for meaning', '

Autor: Viktor Frankl - https://en.wikipedia.org/wiki/Viktor_Frankl

Wiki - https://en.wikipedia.org/wiki/Man%27s_Search_for_Meaning

 

But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?

 

', 0, 0, '2017-12-23T03:39:21.918Z', '2017-12-23T03:40:26.692Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('Iha4YwchR413', '21 - thursday', '', 0, 0, '2017-12-23T03:44:21.176Z', '2017-12-23T03:44:28.816Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('6ZuXjCSWgjB4', 'November', '', 0, 0, '2017-12-23T03:44:45.351Z', '2017-12-23T03:44:53.787Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('GpGnjmcAPeWG', '28', '', 0, 0, '2017-12-23T03:44:57.036Z', '2017-12-23T03:45:08.790Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('21K84UqGhqlt', 'Christmas gift ideas', '', 0, 0, '2017-12-23T03:45:10.933Z', '2017-12-23T16:43:28.160Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('rz5t0r9Qr2WC', 'Epics', '

Epic is kind of medium-term events or projects spread over days or months.

 

Remember that Trilium is all free form so you can organise your stuff in whatever way you''d like

 

 

', 0, 0, '2017-12-23T03:45:20.914Z', '2017-12-23T03:52:37.779Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('R6pheWjdwmNU', 'Christmas', '

This christmas is going to be awesome!

', 0, 0, '2017-12-23T03:45:28.002Z', '2017-12-23T16:42:53.142Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('5v5Dx6LMHXIO', 'Christmas shopping', '

Bought a book!

', 0, 0, '2017-12-23T03:45:44.184Z', '2017-12-23T04:09:15.442Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('MLQjmREtcnJ3', 'Shopping', '', 0, 0, '2017-12-23T03:47:48.208Z', '2017-12-23T03:47:51.917Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('pTTjrxgnvURB', 'Vacation days', '

25. 12., 26. 12., 1. 1. - statutory holidays

27. 12. - 29. 12., 2. 1. - vacation days

', 0, 0, '2017-12-23T03:47:55.932Z', '2017-12-23T03:49:46.419Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('cFK9sGYZaMWs', 'Vacation in Cuba', 'Planning stuff etc.', 0, 0, '2017-12-23T03:49:32.210Z', '2017-12-23T03:55:17.763Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('pOFVzbXLmzhX', 'Christmas dinner', 'Carp of course!', 0, 0, '2017-12-23T03:54:46.138Z', '2017-12-23T03:54:57.762Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('0xtvjqrcGiRB', 'History', '

The history of Linux began in 1991 with the commencement of a personal project by Finnish student Linus Torvalds to create a new free operating system kernel. Since then, the resulting Linux kernel has been marked by constant growth throughout its history. Since the initial release of its source code in 1991, it has grown from a small number of C files under a license prohibiting commercial distribution to the 4.2.3 version in 2015 with more than 18 million lines of source code under the GNU General Public License v2.

', 0, 0, '2017-12-23T04:01:51.565Z', '2017-12-23T04:02:05.496Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('Zl69uXBSen0w', 'Ubuntu', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T04:02:16.685Z', '2017-12-23T18:08:15.381Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('62BKAQMVP2KW', 'Unity shortcuts', '', 0, 0, '2017-12-23T04:02:39.164Z', '2017-12-23T04:03:09.867Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('h4OfLEAYspud', 'Security', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T04:04:00.715Z', '2017-12-23T18:08:25.474Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('1hASbLRDL7oo', 'Trusted timestamping', '

Wiki: https://en.wikipedia.org/wiki/Trusted_timestamping

Bozho: https://techblog.bozho.net/using-trusted-timestamping-java/

 

Trusted timestamping is the process of securely keeping track of the creation and modification time of a document. Security here means that no one—not even the owner of the document—should be able to change it once it has been recorded provided that the timestamper''s integrity is never compromised.

The administrative aspect involves setting up a publicly available, trusted timestamp management infrastructure to collect, process and renew timestamps.

', 0, 0, '2017-12-23T04:04:08.155Z', '2017-12-23T04:04:30.386Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('jyqG9GucsMdn', 'Office party', 'That was fun!', 0, 0, '2017-12-23T04:05:16.439Z', '2017-12-23T04:05:30.373Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('WdWZFuWNVDZk', 'Tech', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T04:06:16.179Z', '2017-12-23T18:08:05.376Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('yK4SBJfwD3tY', 'Work', '

Expand note on the left pane to see content.

', 0, 0, '2017-12-23T04:06:32.833Z', '2017-12-23T18:08:30.573Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('r4BnsmSQeVr1', 'HR', '

HR stuff 

', 0, 0, '2017-12-23T04:06:37.427Z', '2017-12-23T16:42:23.145Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('QbL3pTvhgzM8', 'Processes', '

No content.

 

', 0, 0, '2017-12-23T04:06:43.841Z', '2017-12-23T16:42:15.893Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('moMbTKwN15Ps', 'Projects', '

Here I''d keep various notes related to my work''s projects etc.

', 0, 0, '2017-12-23T04:06:49.331Z', '2017-12-23T04:07:25.429Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('PEGQGg0In3Ar', 'Phone call about work project', '

Bla bla bla ....

', 0, 0, '2017-12-23T16:44:35.900Z', '2017-12-23T16:44:53.174Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('IlULcDiOTI4K', 'Inbox', '

This is a place I use to put notes waiting for better categorization

 

', 0, 0, '2017-12-23T16:45:11.047Z', '2017-12-23T18:04:49.545Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('vBv6ovBupfTj', 'Grocery list for today', '

 

', 0, 0, '2017-12-23T18:04:50.904Z', '2017-12-23T18:05:19.574Z'); +INSERT INTO notes (note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified) VALUES ('mw4f2xB4J5fV', 'Book to read', '

How to be a stoic from Massimo Pigliuci:

 

https://www.amazon.com/gp/product/B01K3WN1BY?pf_rd_m=A2R2RITDJNW1Q6&storeType=ebooks&pageType=STOREFRONT&pf_rd_p=8e2a96d9-c848-435b-92bd-0856850ad544&pf_rd_r=4J6CT15BS4X8062XNGDF&pf_rd_s=merchandised-search-5&pf_rd_t=40901&ref_=dbs_f_ebk_rwt_scns_mwl_ms5_kmw_8e2a96d9-c848-435b-92bd-0856850ad544_2&pf_rd_i=154606011

', 0, 0, '2017-12-23T18:05:24.868Z', '2017-12-23T18:06:55.320Z'); \ No newline at end of file diff --git a/db/main_notes_tree.sql b/db/main_notes_tree.sql new file mode 100644 index 000000000..e95022279 --- /dev/null +++ b/db/main_notes_tree.sql @@ -0,0 +1,52 @@ +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('dLgtLUFn3GoN', '1Heh2acXfPNt', 'root', 21, null, 1, 0, '2017-12-23T00:46:39.304Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('QLfS835GSfIh', '3RkyK9LI18dO', '1Heh2acXfPNt', 1, null, 1, 0, '2017-12-23T01:20:04.181Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('QJAcYJ1gGUh9', 'L1Ox40M1aEyy', '3RkyK9LI18dO', 0, null, 0, 0, '2017-12-23T01:20:45.365Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('wLTa2l3lYi83', 'HJusZTbBU494', '3RkyK9LI18dO', 2, null, 1, 0, '2017-12-23T01:20:50.709Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('yMhwsE7uvEij', '3oldoiMUPOlr', 'HJusZTbBU494', 1, null, 1, 0, '2017-12-23T01:20:55.775Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('EjQTcVVHFmmZ', 'MG0wntwILQW6', '3oldoiMUPOlr', 1, null, 1, 0, '2017-12-23T01:21:10.517Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('jvhKcwz4pYTr', 'ZC78NlmdXeC6', 'WdWZFuWNVDZk', 0, null, 1, 0, '2017-12-23T04:06:21.579Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('CarTrwkGVcPz', 'NncfGH8dyNjJ', 'WdWZFuWNVDZk', 1, null, 0, 0, '2017-12-23T04:06:24.012Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('6M7qPlr7at6N', 'eouCLkjbruai', 'NncfGH8dyNjJ', 0, null, 0, 0, '2017-12-23T01:23:28.291Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('tQgognnAH9WI', 'C44aq4mkaX67', 'NncfGH8dyNjJ', 1, null, 0, 0, '2017-12-23T01:23:31.879Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('xyAi7MmgvAgR', 'C44aq4mkaX67', 'ZC78NlmdXeC6', 1, null, 0, 0, '2017-12-23T01:23:47.756Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('xQ3fjRp9yaPq', 'I6Cw88AirBBl', 'C44aq4mkaX67', 0, null, 0, 0, '2017-12-23T01:24:04.681Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('2GOsNT5LsvTP', 'mcEwFMSjhlvL', 'C44aq4mkaX67', 1, null, 0, 0, '2017-12-23T01:29:35.974Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('RxUiraiR655R', 'CF2lUIJAr6Ey', 'NncfGH8dyNjJ', 2, null, 0, 0, '2017-12-23T01:34:37.658Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('mZuSrZ18Zmv0', 'xkXwueRoDNeN', 'MG0wntwILQW6', 0, null, 0, 0, '2017-12-23T01:35:40.306Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('hbcWTnEnXPwF', 'eXHZAKsMYgur', '1Heh2acXfPNt', 3, null, 1, 0, '2017-12-23T03:32:42.868Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('8a3aNxjG0nu7', '2WU27ekfy07E', 'eXHZAKsMYgur', 0, null, 0, 0, '2017-12-23T03:32:49.379Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('4Tu6vaPdCxCM', 'TjWEndYCCg7g', 'eXHZAKsMYgur', 1, null, 0, 0, '2017-12-23T03:33:23.584Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('lBPOmhP12egP', '8nRNDJGyGs2Z', 'TjWEndYCCg7g', 0, null, 0, 0, '2017-12-23T03:33:37.327Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('C5ipVqeDWySp', '9zSwD89vgzNO', '8nRNDJGyGs2Z', 0, null, 0, 0, '2017-12-23T03:37:04.912Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('uSitzbGcSATJ', 'u5t1EvWa3CMO', 'TjWEndYCCg7g', 1, null, 0, 0, '2017-12-23T03:39:21.918Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('GZ6aRI8rdSJt', '8nRNDJGyGs2Z', 'MG0wntwILQW6', 1, '', 0, 0, '2017-12-23T03:42:28.310Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('HsN4600rQoL9', 'Iha4YwchR413', '3oldoiMUPOlr', 0, null, 1, 0, '2017-12-23T03:44:30.945Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('uipfvAfwWRgx', '6ZuXjCSWgjB4', 'HJusZTbBU494', 0, null, 0, 0, '2017-12-23T03:44:54.096Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('nMRpPWWH8WRk', 'GpGnjmcAPeWG', '6ZuXjCSWgjB4', 0, null, 1, 0, '2017-12-23T03:44:57.036Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('c4wt27WNjepw', '21K84UqGhqlt', 'GpGnjmcAPeWG', 0, null, 0, 0, '2017-12-23T03:45:10.933Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('0fpnraUGs9Kl', 'rz5t0r9Qr2WC', 'HJusZTbBU494', 2, null, 1, 0, '2017-12-23T03:45:20.914Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('d8L8zYlLTbym', 'R6pheWjdwmNU', 'rz5t0r9Qr2WC', 0, null, 1, 0, '2017-12-23T03:45:28.002Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('T4USGzfllu5t', '5v5Dx6LMHXIO', 'Iha4YwchR413', 0, null, 0, 0, '2017-12-23T03:45:44.184Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('c4JgFNIobvQW', 'MLQjmREtcnJ3', 'R6pheWjdwmNU', 0, null, 0, 0, '2017-12-23T03:47:48.208Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('nfWjptAU2ZDg', 'pTTjrxgnvURB', 'R6pheWjdwmNU', 1, null, 0, 0, '2017-12-23T03:47:55.932Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('T2ToYBfyPy0g', 'cFK9sGYZaMWs', 'rz5t0r9Qr2WC', 1, null, 0, 0, '2017-12-23T03:49:32.210Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('NG4gbKOnsM3v', '21K84UqGhqlt', 'MLQjmREtcnJ3', 0, '28. 11. 2017', 0, 0, '2017-12-23T03:53:38.110Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('Fstg4tkccO4N', '5v5Dx6LMHXIO', 'MLQjmREtcnJ3', 1, '21. 12. 2017', 0, 0, '2017-12-23T03:53:49.737Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('MN8B7qXDUViO', 'xkXwueRoDNeN', 'MLQjmREtcnJ3', 2, '22. 12. 2017', 0, 0, '2017-12-23T03:53:57.486Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('gSRkHpB7Bu3D', 'pOFVzbXLmzhX', 'R6pheWjdwmNU', 2, null, 0, 0, '2017-12-23T03:54:46.138Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('6brdjeWDOB6w', '0xtvjqrcGiRB', 'ZC78NlmdXeC6', 0, null, 0, 0, '2017-12-23T04:02:06.650Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('AqKUM2zUVFUF', 'Zl69uXBSen0w', 'ZC78NlmdXeC6', 2, null, 1, 0, '2017-12-23T04:02:16.685Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('Ez7NN2WVzRc4', '62BKAQMVP2KW', 'Zl69uXBSen0w', 1, null, 0, 0, '2017-12-23T04:02:39.164Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('t3vVElqMIQVa', 'h4OfLEAYspud', 'WdWZFuWNVDZk', 2, null, 1, 0, '2017-12-23T04:06:25.769Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('O983DHtLpgmr', '1hASbLRDL7oo', 'h4OfLEAYspud', 0, null, 0, 0, '2017-12-23T16:42:26.347Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('RsvL795Mk1bp', '1hASbLRDL7oo', 'GpGnjmcAPeWG', 1, '', 0, 0, '2017-12-23T04:04:56.830Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('79e4hrHLFmx6', 'jyqG9GucsMdn', 'Iha4YwchR413', 1, null, 0, 0, '2017-12-23T04:05:16.439Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('oWO8rctUjf7d', 'WdWZFuWNVDZk', '1Heh2acXfPNt', 5, null, 1, 0, '2017-12-23T04:06:16.179Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('GOxcrZrxalFN', 'yK4SBJfwD3tY', '1Heh2acXfPNt', 8, null, 1, 0, '2017-12-23T04:06:32.833Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('bSPmEvjLzQKU', 'r4BnsmSQeVr1', 'yK4SBJfwD3tY', 0, null, 0, 0, '2017-12-23T04:06:37.427Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('bMtxCD6cwNR9', 'QbL3pTvhgzM8', 'yK4SBJfwD3tY', 2, null, 0, 0, '2017-12-23T04:06:43.841Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('o4ycR7xIi4oI', 'moMbTKwN15Ps', 'yK4SBJfwD3tY', 3, null, 1, 0, '2017-12-23T04:06:49.331Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('abTEhnOsAsSg', 'PEGQGg0In3Ar', 'GpGnjmcAPeWG', 2, null, 0, 0, '2017-12-23T16:44:35.900Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('bryQseMhyzaI', 'IlULcDiOTI4K', '1Heh2acXfPNt', 0, null, 0, 0, '2017-12-23T18:04:26.439Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('ccslPJf3wQV3', 'vBv6ovBupfTj', 'IlULcDiOTI4K', 0, null, 0, 0, '2017-12-23T18:04:50.904Z'); +INSERT INTO notes_tree (note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified) VALUES ('5Dt9YCMn59sY', 'mw4f2xB4J5fV', 'IlULcDiOTI4K', 1, null, 0, 0, '2017-12-23T18:05:24.868Z'); \ No newline at end of file diff --git a/schema.sql b/db/schema.sql similarity index 75% rename from schema.sql rename to db/schema.sql index 2527f3df0..8a5de85cc 100644 --- a/schema.sql +++ b/db/schema.sql @@ -9,63 +9,27 @@ CREATE TABLE IF NOT EXISTS "sync" ( `entity_id` TEXT NOT NULL, `source_id` TEXT NOT NULL, `sync_date` TEXT NOT NULL); -CREATE UNIQUE INDEX `IDX_sync_entity_name_id` ON `sync` ( - `entity_name`, - `entity_id` -); -CREATE INDEX `IDX_sync_sync_date` ON `sync` ( - `sync_date` -); -CREATE TABLE IF NOT EXISTS "event_log" ( - `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - `note_id` TEXT, - `comment` TEXT, - `date_added` TEXT NOT NULL -); -CREATE INDEX `IDX_event_log_date_added` ON `event_log` ( - `date_added` -); -CREATE TABLE IF NOT EXISTS "notes" ( - `note_id` TEXT NOT NULL, - `note_title` TEXT, - `note_text` TEXT, - `is_protected` INT NOT NULL DEFAULT 0, - `is_deleted` INT NOT NULL DEFAULT 0, - `date_created` TEXT NOT NULL, - `date_modified` TEXT NOT NULL, - PRIMARY KEY(`note_id`) -); -CREATE INDEX `IDX_notes_is_deleted` ON `notes` ( - `is_deleted` -); -CREATE TABLE IF NOT EXISTS "notes_history" ( - `note_history_id` TEXT NOT NULL PRIMARY KEY, - `note_id` TEXT NOT NULL, - `note_title` TEXT, - `note_text` TEXT, - `is_protected` INT NOT NULL DEFAULT 0, - `date_modified_from` TEXT NOT NULL, - `date_modified_to` TEXT NOT NULL -); -CREATE INDEX `IDX_notes_history_note_id` ON `notes_history` ( - `note_id` -); -CREATE INDEX `IDX_notes_history_note_date_modified_from` ON `notes_history` ( - `date_modified_from` -); -CREATE INDEX `IDX_notes_history_note_date_modified_to` ON `notes_history` ( - `date_modified_to` -); CREATE TABLE `source_ids` ( `source_id` TEXT NOT NULL, `date_created` TEXT NOT NULL, PRIMARY KEY(`source_id`) ); -CREATE TABLE `recent_notes` ( - 'note_tree_id'TEXT NOT NULL PRIMARY KEY, - `note_path` TEXT NOT NULL, - `date_accessed` TEXT NOT NULL, - is_deleted INT +CREATE TABLE IF NOT EXISTS "notes" ( + `note_id` TEXT NOT NULL, + `note_title` TEXT, + `note_text` TEXT, + `is_protected` INT NOT NULL DEFAULT 0, + `is_deleted` INT NOT NULL DEFAULT 0, + `date_created` TEXT NOT NULL, + `date_modified` TEXT NOT NULL, + PRIMARY KEY(`note_id`) +); +CREATE TABLE `event_log` ( + `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `note_id` TEXT, + `comment` TEXT, + `date_added` TEXT NOT NULL, + FOREIGN KEY(note_id) REFERENCES notes(note_id) ); CREATE TABLE IF NOT EXISTS "notes_tree" ( `note_tree_id` TEXT NOT NULL, @@ -78,10 +42,47 @@ CREATE TABLE IF NOT EXISTS "notes_tree" ( `date_modified` TEXT NOT NULL, PRIMARY KEY(`note_tree_id`) ); -CREATE INDEX `IDX_notes_tree_note_id` ON `notes_tree` ( - `note_id` +CREATE TABLE IF NOT EXISTS "notes_history" ( + `note_history_id` TEXT NOT NULL PRIMARY KEY, + `note_id` TEXT NOT NULL, + `note_title` TEXT, + `note_text` TEXT, + `is_protected` INT NOT NULL DEFAULT 0, + `date_modified_from` TEXT NOT NULL, + `date_modified_to` TEXT NOT NULL +); +CREATE TABLE `recent_notes` ( + `note_tree_id` TEXT NOT NULL PRIMARY KEY, + `note_path` TEXT NOT NULL, + `date_accessed` TEXT NOT NULL, + is_deleted INT +); +CREATE UNIQUE INDEX `IDX_sync_entity_name_id` ON `sync` ( + `entity_name`, + `entity_id` +); +CREATE INDEX `IDX_sync_sync_date` ON `sync` ( + `sync_date` +); +CREATE INDEX `IDX_notes_is_deleted` ON `notes` ( + `is_deleted` +); +CREATE INDEX `IDX_notes_tree_note_tree_id` ON `notes_tree` ( + `note_tree_id` ); CREATE INDEX `IDX_notes_tree_note_id_parent_note_id` ON `notes_tree` ( `note_id`, `parent_note_id` ); +CREATE INDEX `IDX_notes_tree_note_id` ON `notes_tree` ( + `note_id` +); +CREATE INDEX `IDX_notes_history_note_id` ON `notes_history` ( + `note_id` +); +CREATE INDEX `IDX_notes_history_note_date_modified_from` ON `notes_history` ( + `date_modified_from` +); +CREATE INDEX `IDX_notes_history_note_date_modified_to` ON `notes_history` ( + `date_modified_to` +); diff --git a/export-schema.sh b/export-schema.sh index 95cc7655d..b20d1096f 100755 --- a/export-schema.sh +++ b/export-schema.sh @@ -1,3 +1,7 @@ #!/usr/bin/env bash -sqlite3 ~/trilium-data/document.db .schema > schema.sql \ No newline at end of file +SCHEMA_FILE_PATH=db/schema.sql + +sqlite3 ~/trilium-data/document.db .schema > "$SCHEMA_FILE_PATH" + +echo "DB schema exported to $SCHEMA_FILE_PATH" \ No newline at end of file diff --git a/routes/api/cleanup.js b/routes/api/cleanup.js index 8acc75c54..40eef8177 100644 --- a/routes/api/cleanup.js +++ b/routes/api/cleanup.js @@ -6,6 +6,7 @@ const sql = require('../../services/sql'); const utils = require('../../services/utils'); const sync_table = require('../../services/sync_table'); const auth = require('../../services/auth'); +const log = require('../../services/log'); router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, next) => { await sql.doInTransaction(async () => { @@ -14,8 +15,6 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, n .map(noteId => "'" + utils.sanitizeSql(noteId) + "'") .join(', '); - console.log("Note IDS for deletion", noteIdsSql); - await sql.execute(`DELETE FROM event_log WHERE note_id IN (${noteIdsSql})`); await sql.execute(`DELETE FROM notes_history WHERE note_id IN (${noteIdsSql})`); @@ -30,6 +29,8 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, n await sync_table.cleanupSyncRowsForMissingEntities("notes_tree", "note_tree_id"); await sync_table.cleanupSyncRowsForMissingEntities("notes_history", "note_history_id"); await sync_table.cleanupSyncRowsForMissingEntities("recent_notes", "note_tree_id"); + + log.info("Following notes has been completely cleaned from database: " + noteIdsSql); }); res.send({}); @@ -38,6 +39,8 @@ router.post('/cleanup-soft-deleted-items', auth.checkApiAuth, async (req, res, n router.post('/vacuum-database', auth.checkApiAuth, async (req, res, next) => { await sql.execute("VACUUM"); + log.info("Database has been vacuumed."); + res.send({}); }); diff --git a/routes/api/sync.js b/routes/api/sync.js index 51ae446e3..347f07a4a 100644 --- a/routes/api/sync.js +++ b/routes/api/sync.js @@ -9,6 +9,7 @@ const sync_table = require('../../services/sync_table'); const sql = require('../../services/sql'); const options = require('../../services/options'); const content_hash = require('../../services/content_hash'); +const log = require('../../services/log'); router.get('/check', auth.checkApiAuth, async (req, res, next) => { res.send({ @@ -29,6 +30,8 @@ router.post('/fill-sync-rows', auth.checkApiAuth, async (req, res, next) => { await sync_table.fillSyncRows("recent_notes", "note_tree_id"); }); + log.info("Sync rows have been filled."); + res.send({}); }); @@ -38,6 +41,8 @@ router.post('/force-full-sync', auth.checkApiAuth, async (req, res, next) => { await options.setOption('last_synced_push', 0); }); + log.info("Forcing full sync."); + // not awaiting for the job to finish (will probably take a long time) sync.sync(); diff --git a/services/consistency_checks.js b/services/consistency_checks.js index 57b947bdc..cb20e4cdf 100644 --- a/services/consistency_checks.js +++ b/services/consistency_checks.js @@ -8,7 +8,9 @@ async function runCheck(query, errorText, errorList) { const result = await sql.getFirstColumn(query); if (result.length > 0) { - const err = errorText + ": " + result; + const resultText = result.map(val => "'" + val + "'").join(', '); + + const err = errorText + ": " + resultText; errorList.push(err); log.error(err);