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
This commit is contained in:
Dan Stillman 2017-04-18 03:33:09 -04:00
parent 698eb3358a
commit c03a0df226

View File

@ -116,12 +116,20 @@ Zotero.Schema = new function(){
throw new Zotero.DB.IncompatibleVersionException(msg, dbClientVersion); 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'); var schemaVersion = yield _getSchemaSQLVersion('userdata');
// If upgrading userdata, make backup of database first // If upgrading userdata, make backup of database first
if (userdata < schemaVersion) { if (userdata < schemaVersion) {
yield Zotero.DB.backupDatabase(userdata, true); yield Zotero.DB.backupDatabase(userdata, true);
} }
else if (integrityCheck) {
yield Zotero.DB.backupDatabase(false, true);
}
yield Zotero.DB.queryAsync("PRAGMA foreign_keys = false"); yield Zotero.DB.queryAsync("PRAGMA foreign_keys = false");
try { try {
@ -133,6 +141,15 @@ Zotero.Schema = new function(){
if (Zotero.DB.tableExists('customItemTypes')) { if (Zotero.DB.tableExists('customItemTypes')) {
yield _updateCustomTables(updated); 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); updated = yield _migrateUserDataSchema(userdata, options);
yield _updateSchema('triggers'); yield _updateSchema('triggers');
@ -1148,7 +1165,7 @@ Zotero.Schema = new function(){
this.integrityCheck = Zotero.Promise.coroutine(function* (fix) { 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, // Just as a sanity check, make sure combined field tables are populated,
// so that we don't try to wipe out all data // so that we don't try to wipe out all data