fixed primary keys, added indexes

This commit is contained in:
azivner 2017-10-24 20:00:54 -04:00
parent d1981eb6c3
commit 11bfae4007
4 changed files with 58 additions and 1 deletions

View file

@ -0,0 +1,15 @@
CREATE TABLE `notes_history_mig` (
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
`note_id` INT,
`note_title` TEXT,
`note_text` TEXT,
`date_modified_from` INT,
`date_modified_to` INT,
`encryption` INTEGER DEFAULT 0
);
INSERT INTO notes_history (id, note_id, note_title, note_text, date_modified_from, date_modified_to, encryption)
SELECT id, note_id, note_title, note_text, date_modified_from, date_modified_to, encryption FROM notes_history;
DROP TABLE notes_history;
ALTER TABLE notes_history_mig RENAME TO notes_history;

View file

@ -0,0 +1,41 @@
CREATE INDEX `IDX_notes_history_note_id` ON `notes_history` (
`note_id`
);
CREATE INDEX `IDX_images_note_id` ON `images` (
`note_id`
);
CREATE INDEX `IDX_links_note_id` ON `links` (
`note_id`
);
CREATE INDEX `IDX_audit_log_note_id` ON `audit_log` (
`note_id`
);
CREATE INDEX `IDX_audit_log_date_modified` ON `audit_log` (
`date_modified`
);
CREATE TABLE `notes_mig` (
`note_id` TEXT NOT NULL,
`note_title` TEXT,
`note_text` TEXT,
`note_clone_id` TEXT,
`date_created` INT,
`date_modified` INT,
`encryption` INT,
`is_deleted` INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY(`note_id`)
);
INSERT INTO notes_mig (note_id, note_title, note_text, note_clone_id, date_created, date_modified, encryption)
SELECT note_id, note_title, note_text, note_clone_id, date_created, date_modified, encryption FROM notes;
DROP TABLE notes;
ALTER TABLE notes_mig RENAME TO notes;
CREATE INDEX `IDX_notes_is_deleted` ON `notes` (
`is_deleted`
);

View file

@ -45,6 +45,7 @@ $(document).bind('keydown', 'alt+h', showCurrentNoteHistory);
$("#note-history-list").on('change', () => {
const optVal = $("#note-history-list").find(":selected").val();
const historyItem = globalHistoryItems.find(r => r.id == optVal); // non-strict comparison is important here!!!
$("#note-history-title").html(historyItem.note_title);

View file

@ -2,7 +2,7 @@ const backup = require('./backup');
const sql = require('./sql');
const fs = require('fs-extra');
const APP_DB_VERSION = 7;
const APP_DB_VERSION = 9;
const MIGRATIONS_DIR = "./migrations";
async function migrate() {