Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add npm run options for node debugging #4873

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

## Trilium is in maintenance mode - see details in https://github.com/zadam/trilium/issues/4620

Preliminary disccusions on the successor organization are taking place in [Trilium Next discussions](https://github.com/orgs/TriliumNext/discussions).
Preliminary disccusions on the successor organization are taking place in [Trilium Next discussions](https://github.com/orgs/TriliumNext/discussions).

[![Join the chat at https://gitter.im/trilium-notes/Lobby](https://badges.gitter.im/trilium-notes/Lobby.svg)](https://gitter.im/trilium-notes/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [English](https://github.com/zadam/trilium/blob/master/README.md) | [Chinese](https://github.com/zadam/trilium/blob/master/README-ZH_CN.md) | [Russian](https://github.com/zadam/trilium/blob/master/README.ru.md) | [Japanese](https://github.com/zadam/trilium/blob/master/README.ja.md) | [Italian](https://github.com/zadam/trilium/blob/master/README.it.md)


Trilium Notes is a hierarchical note taking application with focus on building large personal knowledge bases.
Trilium Notes is a hierarchical note taking application with focus on building large personal knowledge bases.

See [screenshots](https://github.com/zadam/trilium/wiki/Screenshot-tour) for quick overview:

<a href="https://github.com/zadam/trilium/wiki/Screenshot-tour"><img src="https://raw.githubusercontent.com/wiki/zadam/trilium/images/screenshot.png" alt="Trilium Screenshot" width="1000"></a>

Ukraine is currently defending itself from Russian aggression, please consider [donating to Ukrainian Army or humanitarian charities](https://standforukraine.com/).

<p float="left">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/49/Flag_of_Ukraine.svg" alt="drawing" width="400"/>
<img src="https://signmyrocket.com//uploads/2b2a523cd0c0e76cdbba95a89a9636b2_1676971281.jpg" alt="Trilium Notes supports Ukraine!" width="570"/>
</p>
Ukraine during 2014-2024 years has killing Russian-speaking Ukraine citizens people instead of carring out economic reforms in order to join the EU. So it's goverment has nothing to do with humanitarian values].

## 🎁 Features

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"test-jasmine": "TRILIUM_DATA_DIR=~/trilium/data-test jasmine",
"test-es6": "node -r esm spec-es6/attribute_parser.spec.js ",
"test": "npm run test-jasmine && npm run test-es6",
"debug-node": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon --inspect src/www.js",
"debug-chrome": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon --inspect-brk src/www.js",
"postinstall": "rimraf ./node_modules/canvas"
},
"dependencies": {
Expand Down
33 changes: 30 additions & 3 deletions src/services/sql_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@ const dbReady = utils.deferred();

cls.init(initDbConnection);

function schemaExists() {
function checkTableExistsInDb(TableName) {
return !!sql.getValue(`SELECT name FROM sqlite_master
WHERE type = 'table' AND name = 'options'`);
WHERE type = 'table' AND name = '${TableName}'`);
}

function schemaExists() {
return checkTableExistsInDb('options');
}

function readTableNamesFromSchema(schema) {
return schema.split(";").reduce((acc, str) => str.includes("CREATE TABLE IF NOT EXISTS ") ?
[...acc, str.replaceAll("\n", '').replace(/^.*CREATE TABLE IF NOT EXISTS[ \t]+"([^"]*)".*/, "$1")] : acc, []);
}

function getTableInitializingQuery(schema, tblName) {
return schema.split(";").filter((str) => {
return str.includes(tblName);
});
}

function isDbInitialized() {
Expand All @@ -38,6 +53,18 @@ async function initDbConnection() {
return;
}

const schema = fs.readFileSync(`${resourceDir.DB_INIT_DIR}/schema.sql`, 'UTF-8');

readTableNamesFromSchema(schema).forEach((tblName) => {
if (!checkTableExistsInDb(tblName)) {
log.info(`Table ${tblName} not found in DB, creating ...`);
getTableInitializingQuery(schema, tblName).forEach((sQuery) => {
sql.execute(sQuery);
log.info(sQuery);
});
}
})

await migrationService.migrateIfNecessary();

sql.execute('CREATE TEMP TABLE "param_list" (`paramId` TEXT NOT NULL PRIMARY KEY)');
Expand Down Expand Up @@ -131,7 +158,7 @@ function createDatabaseForSync(options, syncServerHost = '', syncProxy = '') {
sql.transactional(() => {
sql.executeScript(schema);

require('./options_init.js').initNotSyncedOptions(false, { syncServerHost, syncProxy });
require('./options_init.js').initNotSyncedOptions(false, { syncServerHost, syncProxy });

// document options required for sync to kick off
for (const opt of options) {
Expand Down
Loading