From 3d2ef6be015f025e5405730344d4e09f55c0bd55 Mon Sep 17 00:00:00 2001 From: azivner Date: Wed, 13 Jun 2018 19:10:28 -0400 Subject: [PATCH] remove optionId, closes #117 --- .../a2c75661-f9e2-478f-a69f-6a9409e69997.xml | 241 +++++++++--------- db/migrations/0100__remove_optionId.sql | 15 ++ db/schema.sql | 6 +- src/entities/option.js | 4 +- src/services/app_info.js | 2 +- src/services/sync.js | 2 +- 6 files changed, 148 insertions(+), 122 deletions(-) create mode 100644 db/migrations/0100__remove_optionId.sql diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml index f4bf3db24..7c8dd0bfb 100644 --- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml +++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml @@ -142,11 +142,10 @@ parentNoteId 1 sqlite_autoindex_branches_1 - + 1 - INTEGER|0s + TEXT|0s 1 - 1 2 @@ -161,505 +160,517 @@ parentNoteId TEXT|0s 1 - - id + + 1 + eventId + + 1 + + + eventId 1 + sqlite_autoindex_event_log_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 - + 4 TEXT|0s 1 - + 5 BLOB|0s - + 6 INT|0s 1 0 - + 7 TEXT|0s 1 - + 8 TEXT|0s 1 - + 9 TEXT|0s 1 "" - + 1 imageId 1 - + imageId 1 sqlite_autoindex_images_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 - + 4 TEXT|0s 1 '' - + 5 INT|0s 1 0 - + 6 TEXT|0s 1 - + 7 TEXT|0s 1 - + 8 INT|0s 1 - + 9 TEXT|0s 1 "" - + 1 labelId 1 - + noteId - + name value - + labelId 1 sqlite_autoindex_labels_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 - + 4 INT|0s 1 0 - + 5 TEXT|0s 1 - + 6 TEXT|0s 1 - + 7 TEXT|0s 1 "" - + 1 noteImageId 1 - + noteId imageId - + noteId - + imageId - + noteImageId 1 sqlite_autoindex_note_images_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s - + 4 TEXT|0s - + 5 INT|0s 1 0 - + 6 TEXT|0s 1 - + 7 TEXT|0s 1 - + 8 TEXT|0s 1 '' - + 9 TEXT|0s 1 '' - + 10 TEXT|0s 1 "" - + 1 noteRevisionId 1 - + noteId - + dateModifiedFrom - + dateModifiedTo - + noteRevisionId 1 sqlite_autoindex_note_revisions_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 "unnamed" - + 3 TEXT|0s 1 "" - + 4 INT|0s 1 0 - + 5 INT|0s 1 0 - + 6 TEXT|0s 1 - + 7 TEXT|0s 1 - + 8 TEXT|0s 1 'text' - + 9 TEXT|0s 1 'text/html' - + 10 TEXT|0s 1 "" - + 1 noteId 1 - + type - + noteId 1 sqlite_autoindex_notes_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s + 1 - + 3 + TEXT|0s + + + 4 INT|0s - - 4 + + 5 INTEGER|0s 1 0 - - 5 + + 6 TEXT|0s 1 "" - - 6 + + 7 TEXT|0s 1 '1970-01-01T00:00:00.000Z' - + 1 - name + optionId 1 - - name + + optionId 1 sqlite_autoindex_options_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - - 3 - TEXT|0s - 1 - - - 4 - INT|0s - - 5 + 3 TEXT|0s 1 "" - + + 4 + TEXT|0s + 1 + + + 5 + INT|0s + + 1 branchId 1 - + branchId 1 sqlite_autoindex_recent_notes_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 1 sourceId 1 - + sourceId 1 sqlite_autoindex_source_ids_1 - + 1 text|0s - + 2 text|0s - + 3 text|0s - + 4 integer|0s - + 5 text|0s - + 1 - + 2 - + 1 INTEGER|0s 1 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 - + 4 TEXT|0s 1 - + 5 TEXT|0s 1 - + entityName entityId 1 - + syncDate - + id 1 diff --git a/db/migrations/0100__remove_optionId.sql b/db/migrations/0100__remove_optionId.sql new file mode 100644 index 000000000..cda7146bb --- /dev/null +++ b/db/migrations/0100__remove_optionId.sql @@ -0,0 +1,15 @@ +create table options_mig +( + name TEXT not null PRIMARY KEY, + value TEXT, + dateModified INT, + isSynced INTEGER default 0 not null, + hash TEXT default "" not null, + dateCreated TEXT default '1970-01-01T00:00:00.000Z' not null +); + +INSERT INTO options_mig (name, value, dateModified, isSynced, hash, dateCreated) +SELECT name, value, dateModified, isSynced, hash, dateCreated FROM options; + +DROP TABLE options; +ALTER TABLE options_mig RENAME TO options; \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 7a1c3ba3e..176e0b687 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -115,9 +115,10 @@ CREATE INDEX IDX_notes_type CREATE TABLE IF NOT EXISTS "recent_notes" ( `branchId` TEXT NOT NULL PRIMARY KEY, `notePath` TEXT NOT NULL, + hash TEXT DEFAULT "" NOT NULL, `dateCreated` TEXT NOT NULL, isDeleted INT -, hash TEXT DEFAULT "" NOT NULL); +); CREATE TABLE IF NOT EXISTS "event_log" ( `eventId` TEXT NOT NULL PRIMARY KEY, `noteId` TEXT, @@ -126,8 +127,7 @@ CREATE TABLE IF NOT EXISTS "event_log" ( ); CREATE TABLE IF NOT EXISTS "options" ( - optionId TEXT NOT NULL PRIMARY KEY, - name TEXT not null, + name TEXT not null PRIMARY KEY, value TEXT, dateModified INT, isSynced INTEGER default 0 not null, diff --git a/src/entities/option.js b/src/entities/option.js index 2d175fa8c..9bd3ebf06 100644 --- a/src/entities/option.js +++ b/src/entities/option.js @@ -5,8 +5,8 @@ const dateUtils = require('../services/date_utils'); class Option extends Entity { static get tableName() { return "options"; } - static get primaryKeyName() { return "optionId"; } - static get hashedProperties() { return ["optionId", "name", "value"]; } + static get primaryKeyName() { return "name"; } + static get hashedProperties() { return ["name", "value"]; } beforeSaving() { super.beforeSaving(); diff --git a/src/services/app_info.js b/src/services/app_info.js index ba7e24ecf..681414e3f 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -3,7 +3,7 @@ const build = require('./build'); const packageJson = require('../../package'); -const APP_DB_VERSION = 99; +const APP_DB_VERSION = 100; const SYNC_VERSION = 1; module.exports = { diff --git a/src/services/sync.js b/src/services/sync.js index 5a7c47e54..8bc33e1ee 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -205,7 +205,7 @@ const primaryKeys = { "note_images": "noteImageId", "labels": "labelId", "api_tokens": "apiTokenId", - "options": "optionId" + "options": "name" }; async function getEntityRow(entityName, entityId) {