From d730e068b0708c1ed9854b7435af225b47de69e1 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 19 Apr 2020 16:02:10 +0100 Subject: [PATCH] All: Fixes #3088: Better handling of missing table field bug on Linux --- ReactNativeClient/lib/joplin-database.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ReactNativeClient/lib/joplin-database.js b/ReactNativeClient/lib/joplin-database.js index f49bc7c81..5936f80e8 100644 --- a/ReactNativeClient/lib/joplin-database.js +++ b/ReactNativeClient/lib/joplin-database.js @@ -251,7 +251,7 @@ class JoplinDatabase extends Database { return d && d[fieldName] ? d[fieldName] : ''; } - refreshTableFields() { + refreshTableFields(newVersion) { this.logger().info('Initializing tables...'); const queries = []; queries.push(this.wrapQuery('DELETE FROM table_fields')); @@ -289,6 +289,7 @@ class JoplinDatabase extends Database { return promiseChain(chain); }) .then(() => { + queries.push({ sql: 'UPDATE version SET table_fields_version = ?', params: [newVersion] }); return this.transactionExecBatch(queries); }); } @@ -313,7 +314,7 @@ class JoplinDatabase extends Database { // must be set in the synchronizer too. // Note: v16 and v17 don't do anything. They were used to debug an issue. - const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]; + const existingDatabaseVersions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]; let currentVersionIndex = existingDatabaseVersions.indexOf(fromVersion); @@ -681,6 +682,10 @@ class JoplinDatabase extends Database { queries.push('CREATE INDEX resources_size ON resources(size)'); } + if (targetVersion == 29) { + queries.push('ALTER TABLE version ADD COLUMN table_fields_version INT NOT NULL DEFAULT 0'); + } + queries.push({ sql: 'UPDATE version SET version = ?', params: [targetVersion] }); try { @@ -734,12 +739,13 @@ class JoplinDatabase extends Database { } const version = !versionRow ? 0 : versionRow.version; + const tableFieldsVersion = !versionRow ? 0 : versionRow.table_fields_version; this.version_ = version; this.logger().info('Current database version', version); const newVersion = await this.upgradeDatabase(version); this.version_ = newVersion; - if (newVersion !== version) await this.refreshTableFields(); + if (newVersion !== tableFieldsVersion) await this.refreshTableFields(newVersion); this.tableFields_ = {};