www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit c03a0df226f0fcb9544d708d8cd38682806e717f
parent 698eb3358a2fb7ae6dc14db5290475cb66c43e3a
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 18 Apr 2017 03:33:09 -0400

Add settings table flag to auto-repair database on startup

This will allow the DB Repair Tool to only recreate the file and leave
schema knowledge to the client.

Addresses #895

Diffstat:
Mchrome/content/zotero/xpcom/schema.js | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js @@ -116,12 +116,20 @@ Zotero.Schema = new function(){ throw new Zotero.DB.IncompatibleVersionException(msg, dbClientVersion); } + // Check if DB is coming from the DB Repair Tool and should be checked + var integrityCheck = yield Zotero.DB.valueQueryAsync( + "SELECT value FROM settings WHERE setting='db' AND key='integrityCheck'" + ); + var schemaVersion = yield _getSchemaSQLVersion('userdata'); // If upgrading userdata, make backup of database first if (userdata < schemaVersion) { yield Zotero.DB.backupDatabase(userdata, true); } + else if (integrityCheck) { + yield Zotero.DB.backupDatabase(false, true); + } yield Zotero.DB.queryAsync("PRAGMA foreign_keys = false"); try { @@ -133,6 +141,15 @@ Zotero.Schema = new function(){ if (Zotero.DB.tableExists('customItemTypes')) { yield _updateCustomTables(updated); } + + // Auto-repair databases coming from the DB Repair Tool + if (integrityCheck) { + yield this.integrityCheck(true); + yield Zotero.DB.queryAsync( + "DELETE FROM settings WHERE setting='db' AND key='integrityCheck'" + ); + } + updated = yield _migrateUserDataSchema(userdata, options); yield _updateSchema('triggers'); @@ -1148,7 +1165,7 @@ Zotero.Schema = new function(){ this.integrityCheck = Zotero.Promise.coroutine(function* (fix) { - var userLibraryID = Zotero.Libraries.userLibraryID; + Zotero.debug("Checking database integrity"); // Just as a sanity check, make sure combined field tables are populated, // so that we don't try to wipe out all data