From 3033f7cc089be84a62e8a3b29e602fca98303b65 Mon Sep 17 00:00:00 2001 From: azivner Date: Fri, 16 Feb 2018 19:07:59 -0500 Subject: [PATCH] attribute value is now non-null, fixes #52 --- .../0077__non_null_attribute_value.sql | 23 +++++++++++++++++++ src/services/app_info.js | 2 +- src/services/attributes.js | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 db/migrations/0077__non_null_attribute_value.sql diff --git a/db/migrations/0077__non_null_attribute_value.sql b/db/migrations/0077__non_null_attribute_value.sql new file mode 100644 index 000000000..8fac721c6 --- /dev/null +++ b/db/migrations/0077__non_null_attribute_value.sql @@ -0,0 +1,23 @@ +UPDATE attributes SET value = '' WHERE value IS NULL; + +CREATE TABLE IF NOT EXISTS "attributes_mig" +( + attributeId TEXT PRIMARY KEY NOT NULL, + noteId TEXT NOT NULL, + name TEXT NOT NULL, + value TEXT NOT NULL DEFAULT '', + position INT NOT NULL DEFAULT 0, + dateCreated TEXT NOT NULL, + dateModified TEXT NOT NULL, + isDeleted INT NOT NULL +); + +INSERT INTO attributes_mig (attributeId, noteId, name, value, position, dateCreated, dateModified, isDeleted) + SELECT attributeId, noteId, name, value, position, dateCreated, dateModified, isDeleted FROM attributes; + +DROP TABLE attributes; + +ALTER TABLE attributes_mig RENAME TO attributes; + +CREATE INDEX IDX_attributes_noteId ON attributes (noteId); +CREATE INDEX IDX_attributes_name_value ON attributes (name, value); \ No newline at end of file diff --git a/src/services/app_info.js b/src/services/app_info.js index 86f357af0..9335fe759 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 = 76; +const APP_DB_VERSION = 77; module.exports = { app_version: packageJson.version, diff --git a/src/services/attributes.js b/src/services/attributes.js index 12f19bba5..06322349c 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -52,7 +52,7 @@ async function getNoteIdsWithAttribute(name) { WHERE notes.isDeleted = 0 AND attributes.isDeleted = 0 AND attributes.name = ? AND attributes.isDeleted = 0`, [name]); } -async function createAttribute(noteId, name, value = null, sourceId = null) { +async function createAttribute(noteId, name, value = "", sourceId = null) { const now = utils.nowDate(); const attributeId = utils.newAttributeId();