mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 04:16:17 +01:00 
			
		
		
		
	migration script to camel case
This commit is contained in:
		@@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS "notes" (
 | 
				
			|||||||
    `is_protected`	INT NOT NULL DEFAULT 0,
 | 
					    `is_protected`	INT NOT NULL DEFAULT 0,
 | 
				
			||||||
    `is_deleted`	INT NOT NULL DEFAULT 0,
 | 
					    `is_deleted`	INT NOT NULL DEFAULT 0,
 | 
				
			||||||
    `date_created`	TEXT NOT NULL,
 | 
					    `date_created`	TEXT NOT NULL,
 | 
				
			||||||
    `date_modified`	TEXT NOT NULL, type TEXT NOT NULL DEFAULT 'text', mime TEXT NOT NULL DEFAULT 'text',
 | 
					    `date_modified`	TEXT NOT NULL, type TEXT NOT NULL DEFAULT 'text', mime TEXT NOT NULL DEFAULT 'text/html',
 | 
				
			||||||
    PRIMARY KEY(`note_id`)
 | 
					    PRIMARY KEY(`note_id`)
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
CREATE INDEX `IDX_notes_is_deleted` ON `notes` (
 | 
					CREATE INDEX `IDX_notes_is_deleted` ON `notes` (
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										207
									
								
								migrations/0070__rename_columns_to_camel_case.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										207
									
								
								migrations/0070__rename_columns_to_camel_case.sql
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,207 @@
 | 
				
			|||||||
 | 
					CREATE TABLE "options_mig" (
 | 
				
			||||||
 | 
					    `name`	TEXT NOT NULL PRIMARY KEY,
 | 
				
			||||||
 | 
					    `value`	TEXT,
 | 
				
			||||||
 | 
					    `dateModified` INT,
 | 
				
			||||||
 | 
					    isSynced INTEGER NOT NULL DEFAULT 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO options_mig (name, value, dateModified, isSynced)
 | 
				
			||||||
 | 
					    SELECT opt_name, opt_value, date_modified, is_synced FROM options;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE options;
 | 
				
			||||||
 | 
					ALTER TABLE options_mig RENAME TO options;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE "sync_mig" (
 | 
				
			||||||
 | 
					  `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
 | 
				
			||||||
 | 
					  `entityName`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `entityId`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `sourceId` TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `syncDate`	TEXT NOT NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO sync_mig (id, entityName, entityId, sourceId, syncDate)
 | 
				
			||||||
 | 
					    SELECT id, entity_name, entity_id, source_id, sync_date FROM sync;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE sync;
 | 
				
			||||||
 | 
					ALTER TABLE sync_mig RENAME TO sync;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE UNIQUE INDEX `IDX_sync_entityName_entityId` ON `sync` (
 | 
				
			||||||
 | 
					  `entityName`,
 | 
				
			||||||
 | 
					  `entityId`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX `IDX_sync_syncDate` ON `sync` (
 | 
				
			||||||
 | 
					  `syncDate`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `source_ids_mig` (
 | 
				
			||||||
 | 
					  `sourceId`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `dateCreated`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  PRIMARY KEY(`sourceId`)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO source_ids_mig (sourceId, dateCreated)
 | 
				
			||||||
 | 
					    SELECT source_id, date_created FROM source_ids;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE source_ids;
 | 
				
			||||||
 | 
					ALTER TABLE source_ids_mig RENAME TO source_ids;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE "notes_mig" (
 | 
				
			||||||
 | 
					  `noteId`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `title`	TEXT,
 | 
				
			||||||
 | 
					  `content`	TEXT,
 | 
				
			||||||
 | 
					  `isProtected`	INT NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					  `isDeleted`	INT NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					  `dateCreated`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `dateModified`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  type TEXT NOT NULL DEFAULT 'text',
 | 
				
			||||||
 | 
					  mime TEXT NOT NULL DEFAULT 'text/html',
 | 
				
			||||||
 | 
					  PRIMARY KEY(`noteId`)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO notes_mig (noteId, title, content, isProtected, isDeleted, dateCreated, dateModified, type, mime)
 | 
				
			||||||
 | 
					    SELECT note_id, note_title, note_text, is_protected, is_deleted, date_created, date_modified, type, mime FROM notes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE notes;
 | 
				
			||||||
 | 
					ALTER TABLE notes_mig RENAME TO notes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX `IDX_notes_isDeleted` ON `notes` (
 | 
				
			||||||
 | 
					  `isDeleted`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `event_log_mig` (
 | 
				
			||||||
 | 
					  `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
 | 
				
			||||||
 | 
					  `noteId`	TEXT,
 | 
				
			||||||
 | 
					  `comment`	TEXT,
 | 
				
			||||||
 | 
					  `dateAdded`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  FOREIGN KEY(noteId) REFERENCES notes(noteId)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO event_log_mig (id, noteId, comment, dateAdded)
 | 
				
			||||||
 | 
					    SELECT id, note_id, comment, date_added FROM event_log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE event_log;
 | 
				
			||||||
 | 
					ALTER TABLE event_log_mig RENAME TO event_log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE "note_tree" (
 | 
				
			||||||
 | 
					  `noteTreeId`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `noteId`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `parentNoteId`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `notePosition`	INTEGER NOT NULL,
 | 
				
			||||||
 | 
					  `prefix`	TEXT,
 | 
				
			||||||
 | 
					  `isExpanded`	BOOLEAN,
 | 
				
			||||||
 | 
					  `isDeleted`	INTEGER NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					  `dateModified`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  PRIMARY KEY(`noteTreeId`)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO note_tree (noteTreeId, noteId, parentNoteId, notePosition, prefix, isExpanded, isDeleted, dateModified)
 | 
				
			||||||
 | 
					    SELECT note_tree_id, note_id, parent_note_id, note_position, prefix, is_expanded, is_deleted, date_modified FROM notes_tree;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE notes_tree;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX `IDX_note_tree_noteId` ON `note_tree` (
 | 
				
			||||||
 | 
					  `noteId`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX `IDX_note_tree_noteId_parentNoteId` ON `note_tree` (
 | 
				
			||||||
 | 
					  `noteId`,
 | 
				
			||||||
 | 
					  `parentNoteId`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE "note_revisions" (
 | 
				
			||||||
 | 
					  `noteRevisionId`	TEXT NOT NULL PRIMARY KEY,
 | 
				
			||||||
 | 
					  `noteId`	TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `title`	TEXT,
 | 
				
			||||||
 | 
					  `content`	TEXT,
 | 
				
			||||||
 | 
					  `isProtected`	INT NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					  `dateModifiedFrom` TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `dateModifiedTo` TEXT NOT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO note_revisions (noteRevisionId, noteId, title, content, isProtected, dateModifiedFrom, dateModifiedTo)
 | 
				
			||||||
 | 
					    SELECT note_history_id, note_id, note_title, note_text, is_protected, date_modified_from, date_modified_to FROM notes_history;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE notes_history;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (
 | 
				
			||||||
 | 
					  `noteId`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX `IDX_note_revisions_dateModifiedFrom` ON `note_revisions` (
 | 
				
			||||||
 | 
					  `dateModifiedFrom`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX `IDX_note_revisions_dateModifiedTo` ON `note_revisions` (
 | 
				
			||||||
 | 
					  `dateModifiedTo`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `recent_notes_mig` (
 | 
				
			||||||
 | 
					  `noteTreeId` TEXT NOT NULL PRIMARY KEY,
 | 
				
			||||||
 | 
					  `notePath` TEXT NOT NULL,
 | 
				
			||||||
 | 
					  `dateAccessed` TEXT NOT NULL,
 | 
				
			||||||
 | 
					  isDeleted INT
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO recent_notes_mig (noteTreeId, notePath, dateAccessed, isDeleted)
 | 
				
			||||||
 | 
					    SELECT note_tree_id, note_path, date_accessed, is_deleted FROM recent_notes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE recent_notes;
 | 
				
			||||||
 | 
					ALTER TABLE recent_notes_mig RENAME TO recent_notes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE images_mig
 | 
				
			||||||
 | 
					(
 | 
				
			||||||
 | 
					  imageId TEXT PRIMARY KEY NOT NULL,
 | 
				
			||||||
 | 
					  format TEXT NOT NULL,
 | 
				
			||||||
 | 
					  checksum TEXT NOT NULL,
 | 
				
			||||||
 | 
					  name TEXT NOT NULL,
 | 
				
			||||||
 | 
					  data BLOB,
 | 
				
			||||||
 | 
					  isDeleted INT NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					  dateModified TEXT NOT NULL,
 | 
				
			||||||
 | 
					  dateCreated TEXT NOT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO images_mig (imageId, format, checksum, name, data, isDeleted, dateModified, dateCreated)
 | 
				
			||||||
 | 
					    SELECT image_id, format, checksum, name, data, is_deleted, date_modified, date_created FROM images;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE images;
 | 
				
			||||||
 | 
					ALTER TABLE images_mig RENAME TO images;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE note_images
 | 
				
			||||||
 | 
					(
 | 
				
			||||||
 | 
					  noteImageId TEXT PRIMARY KEY NOT NULL,
 | 
				
			||||||
 | 
					  noteId TEXT NOT NULL,
 | 
				
			||||||
 | 
					  imageId TEXT NOT NULL,
 | 
				
			||||||
 | 
					  isDeleted INT NOT NULL DEFAULT 0,
 | 
				
			||||||
 | 
					  dateModified TEXT NOT NULL,
 | 
				
			||||||
 | 
					  dateCreated TEXT NOT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO note_images (noteImageId, noteId, imageId, isDeleted, dateModified, dateCreated)
 | 
				
			||||||
 | 
					    SELECT note_image_id, note_id, image_id, is_deleted, date_modified, date_created FROM notes_image;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE notes_image;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX IDX_note_images_noteId ON note_images (noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX IDX_note_images_imageId ON note_images (imageId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX IDX_note_images_noteId_imageId ON note_images (noteId, imageId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE attributes_mig
 | 
				
			||||||
 | 
					(
 | 
				
			||||||
 | 
					  attributeId TEXT PRIMARY KEY NOT NULL,
 | 
				
			||||||
 | 
					  noteId TEXT NOT NULL,
 | 
				
			||||||
 | 
					  name TEXT NOT NULL,
 | 
				
			||||||
 | 
					  value TEXT,
 | 
				
			||||||
 | 
					  dateCreated TEXT NOT NULL,
 | 
				
			||||||
 | 
					  dateModified TEXT NOT NULL
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO attributes_mig (attributeId, noteId, name, value, dateCreated, dateModified)
 | 
				
			||||||
 | 
					    SELECT attribute_id, note_id, name, value, date_created, date_modified FROM attributes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DROP TABLE attributes;
 | 
				
			||||||
 | 
					ALTER TABLE attributes_mig RENAME TO attributes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE INDEX IDX_attributes_noteId ON attributes (noteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE UNIQUE INDEX IDX_attributes_noteId_name ON attributes (noteId, name);
 | 
				
			||||||
@@ -642,7 +642,7 @@ const noteTree = (function() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    function loadTree() {
 | 
					    function loadTree() {
 | 
				
			||||||
        return server.get('tree').then(resp => {
 | 
					        return server.get('tree').then(resp => {
 | 
				
			||||||
            startNotePath = resp.start_notePath;
 | 
					            startNotePath = resp.start_note_path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (document.location.hash) {
 | 
					            if (document.location.hash) {
 | 
				
			||||||
                startNotePath = getNotePathFromAddress();
 | 
					                startNotePath = getNotePathFromAddress();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ const express = require('express');
 | 
				
			|||||||
const router = express.Router();
 | 
					const router = express.Router();
 | 
				
			||||||
const options = require('../../services/options');
 | 
					const options = require('../../services/options');
 | 
				
			||||||
const utils = require('../../services/utils');
 | 
					const utils = require('../../services/utils');
 | 
				
			||||||
const sourceId = require('../../services/sourceId');
 | 
					const sourceId = require('../../services/source_id');
 | 
				
			||||||
const auth = require('../../services/auth');
 | 
					const auth = require('../../services/auth');
 | 
				
			||||||
const password_encryption = require('../../services/password_encryption');
 | 
					const password_encryption = require('../../services/password_encryption');
 | 
				
			||||||
const protected_session = require('../../services/protected_session');
 | 
					const protected_session = require('../../services/protected_session');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,7 +28,7 @@ router.put('/:noteTreeId/:notePath', auth.checkApiAuth, wrap(async (req, res, ne
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        await sync_table.addRecentNoteSync(noteTreeId, sourceId);
 | 
					        await sync_table.addRecentNoteSync(noteTreeId, sourceId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        await options.setOption('start_notePath', notePath, sourceId);
 | 
					        await options.setOption('start_note_path', notePath, sourceId);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.send(await getRecentNotes());
 | 
					    res.send(await getRecentNotes());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,7 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    res.send({
 | 
					    res.send({
 | 
				
			||||||
        notes: notes,
 | 
					        notes: notes,
 | 
				
			||||||
        start_notePath: await options.getOption('start_notePath')
 | 
					        start_note_path: await options.getOption('start_note_path')
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}));
 | 
					}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@
 | 
				
			|||||||
const express = require('express');
 | 
					const express = require('express');
 | 
				
			||||||
const router = express.Router();
 | 
					const router = express.Router();
 | 
				
			||||||
const auth = require('../services/auth');
 | 
					const auth = require('../services/auth');
 | 
				
			||||||
const sourceId = require('../services/sourceId');
 | 
					const sourceId = require('../services/source_id');
 | 
				
			||||||
const sql = require('../services/sql');
 | 
					const sql = require('../services/sql');
 | 
				
			||||||
const wrap = require('express-promise-wrap').wrap;
 | 
					const wrap = require('express-promise-wrap').wrap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@
 | 
				
			|||||||
const build = require('./build');
 | 
					const build = require('./build');
 | 
				
			||||||
const packageJson = require('../package');
 | 
					const packageJson = require('../package');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const APP_DB_VERSION = 69;
 | 
					const APP_DB_VERSION = 70;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
    app_version: packageJson.version,
 | 
					    app_version: packageJson.version,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,8 +4,13 @@ const sync_table = require('./sync_table');
 | 
				
			|||||||
const app_info = require('./app_info');
 | 
					const app_info = require('./app_info');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getOptionOrNull(name) {
 | 
					async function getOptionOrNull(name) {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
        return await sql.getFirstOrNull("SELECT value FROM options WHERE name = ?", [name]);
 | 
					        return await sql.getFirstOrNull("SELECT value FROM options WHERE name = ?", [name]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    catch (e) {
 | 
				
			||||||
 | 
					        return await sql.getFirstOrNull("SELECT opt_value FROM options WHERE opt_name = ?", [name]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getOption(name) {
 | 
					async function getOption(name) {
 | 
				
			||||||
    const row = await getOptionOrNull(name);
 | 
					    const row = await getOptionOrNull(name);
 | 
				
			||||||
@@ -14,11 +19,18 @@ async function getOption(name) {
 | 
				
			|||||||
        throw new Error("Option " + name + " doesn't exist");
 | 
					        throw new Error("Option " + name + " doesn't exist");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return row['value'];
 | 
					    return row['value'] ? row['value'] : row['opt_value'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function setOption(name, value, sourceId = null) {
 | 
					async function setOption(name, value, sourceId = null) {
 | 
				
			||||||
    const opt = await sql.getFirst("SELECT * FROM options WHERE name = ?", [name]);
 | 
					    let opt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        opt = await sql.getFirst("SELECT * FROM options WHERE name = ?", [name]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    catch (e) {
 | 
				
			||||||
 | 
					        opt = await sql.getFirst("SELECT * FROM options WHERE opt_name = ?", [name]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!opt) {
 | 
					    if (!opt) {
 | 
				
			||||||
        throw new Error(`Option ${name} doesn't exist`);
 | 
					        throw new Error(`Option ${name} doesn't exist`);
 | 
				
			||||||
@@ -28,9 +40,15 @@ async function setOption(name, value, sourceId = null) {
 | 
				
			|||||||
        await sync_table.addOptionsSync(name, sourceId);
 | 
					        await sync_table.addOptionsSync(name, sourceId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
        await sql.execute("UPDATE options SET value = ?, dateModified = ? WHERE name = ?",
 | 
					        await sql.execute("UPDATE options SET value = ?, dateModified = ? WHERE name = ?",
 | 
				
			||||||
            [value, utils.nowDate(), name]);
 | 
					            [value, utils.nowDate(), name]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    catch (e) {
 | 
				
			||||||
 | 
					        await sql.execute("UPDATE options SET opt_value = ?, date_modified = ? WHERE opt_name = ?",
 | 
				
			||||||
 | 
					            [value, utils.nowDate(), name]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function createOption(name, value, isSynced, sourceId = null) {
 | 
					async function createOption(name, value, isSynced, sourceId = null) {
 | 
				
			||||||
    await sql.insert("options", {
 | 
					    await sql.insert("options", {
 | 
				
			||||||
@@ -56,7 +74,7 @@ async function initOptions(startNotePath) {
 | 
				
			|||||||
    await createOption('encrypted_data_key', '', true);
 | 
					    await createOption('encrypted_data_key', '', true);
 | 
				
			||||||
    await createOption('encrypted_data_key_iv', '', true);
 | 
					    await createOption('encrypted_data_key_iv', '', true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await createOption('start_notePath', startNotePath, false);
 | 
					    await createOption('start_note_path', startNotePath, false);
 | 
				
			||||||
    await createOption('protected_session_timeout', 600, true);
 | 
					    await createOption('protected_session_timeout', 600, true);
 | 
				
			||||||
    await createOption('history_snapshot_time_interval', 600, true);
 | 
					    await createOption('history_snapshot_time_interval', 600, true);
 | 
				
			||||||
    await createOption('last_backup_date', utils.nowDate(), false);
 | 
					    await createOption('last_backup_date', utils.nowDate(), false);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,7 +61,7 @@ function ScriptContext(noteId, dataKey) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (!note.type) {
 | 
					        if (!note.type) {
 | 
				
			||||||
            note.type = "text";
 | 
					            note.type = "text";
 | 
				
			||||||
            note.mime = "";
 | 
					            note.mime = "text/html";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const noteId = (await notes.createNewNote(parentNoteId, note)).noteId;
 | 
					        const noteId = (await notes.createNewNote(parentNoteId, note)).noteId;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ const sql = require('./sql');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
async function saveSourceId(sourceId) {
 | 
					async function saveSourceId(sourceId) {
 | 
				
			||||||
    await sql.doInTransaction(async () => {
 | 
					    await sql.doInTransaction(async () => {
 | 
				
			||||||
        await sql.insert("sourceIds", {
 | 
					        await sql.insert("source_ids", {
 | 
				
			||||||
            sourceId: sourceId,
 | 
					            sourceId: sourceId,
 | 
				
			||||||
            dateCreated: utils.nowDate()
 | 
					            dateCreated: utils.nowDate()
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -226,7 +226,14 @@ async function doInTransaction(func) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function isDbUpToDate() {
 | 
					async function isDbUpToDate() {
 | 
				
			||||||
    const dbVersion = parseInt(await getFirstValue("SELECT value FROM options WHERE name = 'db_version'"));
 | 
					    let dbVersion;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        dbVersion = parseInt(await getFirstValue("SELECT value FROM options WHERE name = 'db_version'"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    catch (e) {
 | 
				
			||||||
 | 
					        dbVersion = parseInt(await getFirstValue("SELECT opt_value FROM options WHERE opt_name = 'db_version'"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const upToDate = dbVersion >= app_info.db_version;
 | 
					    const upToDate = dbVersion >= app_info.db_version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -238,7 +245,14 @@ async function isDbUpToDate() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function isUserInitialized() {
 | 
					async function isUserInitialized() {
 | 
				
			||||||
    const username = await getFirstValue("SELECT value FROM options WHERE name = 'username'");
 | 
					    let username;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					        username = await getFirstValue("SELECT value FROM options WHERE name = 'username'");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    catch (e) {
 | 
				
			||||||
 | 
					        username = await getFirstValue("SELECT opt_value FROM options WHERE opt_name = 'username'");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return !!username;
 | 
					    return !!username;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ const rp = require('request-promise');
 | 
				
			|||||||
const sql = require('./sql');
 | 
					const sql = require('./sql');
 | 
				
			||||||
const options = require('./options');
 | 
					const options = require('./options');
 | 
				
			||||||
const utils = require('./utils');
 | 
					const utils = require('./utils');
 | 
				
			||||||
const sourceId = require('./sourceId');
 | 
					const sourceId = require('./source_id');
 | 
				
			||||||
const notes = require('./notes');
 | 
					const notes = require('./notes');
 | 
				
			||||||
const syncUpdate = require('./sync_update');
 | 
					const syncUpdate = require('./sync_update');
 | 
				
			||||||
const content_hash = require('./content_hash');
 | 
					const content_hash = require('./content_hash');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
const sql = require('./sql');
 | 
					const sql = require('./sql');
 | 
				
			||||||
const sourceId = require('./sourceId');
 | 
					const sourceId = require('./source_id');
 | 
				
			||||||
const utils = require('./utils');
 | 
					const utils = require('./utils');
 | 
				
			||||||
const sync_setup = require('./sync_setup');
 | 
					const sync_setup = require('./sync_setup');
 | 
				
			||||||
const log = require('./log');
 | 
					const log = require('./log');
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user