From feaeac512da93d73854ff2bafdb88ba334130756 Mon Sep 17 00:00:00 2001 From: alifirat Date: Tue, 5 Jul 2022 01:09:07 +0300 Subject: [PATCH] notes triggers bug fix --- public/background.js | 4 +- public/migrations/20220702133706_notes.js | 6 +- .../20220702140834_notes_triggers.js | 60 ++++++++++++------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/public/background.js b/public/background.js index aba77ab..9428197 100644 --- a/public/background.js +++ b/public/background.js @@ -24,9 +24,9 @@ protocol.registerSchemesAsPrivileged( ); async function setup() { - let D_OK = await fs.pathExists(path.join(os.homedir(), 'Not')); + let D_OK = await fs.pathExists(path.join(os.homedir(), 'Note')); if (D_OK === false) { - await fs.ensureDir(path.join(os.homedir(), 'Not')); + await fs.ensureDir(path.join(os.homedir(), 'Note')); } let cparams = { diff --git a/public/migrations/20220702133706_notes.js b/public/migrations/20220702133706_notes.js index be2afb1..de07635 100644 --- a/public/migrations/20220702133706_notes.js +++ b/public/migrations/20220702133706_notes.js @@ -4,9 +4,9 @@ */ exports.up = function (knex) { return knex.schema.createTable('notes', table => { - table.increments('id').primary(); - table.string('title').notNullable(); - table.string('notebook').notNullable().index(); + table.increments('id').primary().index(); + table.string('title', 100).notNullable(); + table.string('notebook', 100).notNullable().index(); table.text('contents').notNullable(); table.timestamps(true, true, true); diff --git a/public/migrations/20220702140834_notes_triggers.js b/public/migrations/20220702140834_notes_triggers.js index 5955779..95f23c2 100644 --- a/public/migrations/20220702140834_notes_triggers.js +++ b/public/migrations/20220702140834_notes_triggers.js @@ -3,28 +3,48 @@ * @returns { Promise } */ exports.up = function (knex) { - return knex.raw(` - CREATE TRIGGER notes_insert AFTER INSERT ON notes - BEGIN - INSERT INTO notes_fts (rowid, title, notebook, contents) - VALUES (new.id, new.title, new.notebook, new.contents); - END; + let raws = []; + //------------------------------------- + raws.push( + knex.raw( + ` + CREATE TRIGGER notes_insert AFTER INSERT ON notes + BEGIN + INSERT INTO notes_fts (rowid, title, notebook, contents) + VALUES (new.id, new.title, new.notebook, new.contents); + END; + ` + ) + ); - CREATE TRIGGER notes_delete AFTER DELETE ON notes - BEGIN - INSERT INTO notes_fts (notes_fts, rowid, title, notebook, contents) - VALUES ('delete', old.id, old.title, old.notebook, old.contents); - END; + raws.push( + knex.raw( + ` + CREATE TRIGGER notes_delete AFTER DELETE ON notes + BEGIN + INSERT INTO notes_fts (notes_fts, rowid, title, notebook, contents) + VALUES ('delete', old.id, old.title, old.notebook, old.contents); + END; + ` + ) + ); - CREATE TRIGGER notes_update AFTER UPDATE ON notes - BEGIN - INSERT INTO notes_fts (notes_fts, rowid, title, notebook, contents) - VALUES ('delete', old.id, old.title, old.notebook, old.contents); - - INSERT INTO notes_fts (rowid, title, notebook, contents) - VALUES (new.id, new.title, new.notebook, new.contents); - END; - `); + raws.push( + knex.raw( + ` + CREATE TRIGGER notes_update AFTER UPDATE ON notes + BEGIN + INSERT INTO notes_fts (notes_fts, rowid, title, notebook, contents) + VALUES ('delete', old.id, old.title, old.notebook, old.contents); + + INSERT INTO notes_fts (rowid, title, notebook, contents) + VALUES (new.id, new.title, new.notebook, new.contents); + END; + ` + ) + ); + + return Promise.all(raws); }; /**