Disable foreign key checks during schema modifications

Otherwise renaming a table causes existing foreign keys to be renamed.
This commit is contained in:
Dan Stillman 2015-12-29 23:37:45 -05:00
parent 8933e3b586
commit 6844deba60

View file

@ -117,9 +117,9 @@ Zotero.Schema = new function(){
yield Zotero.DB.backupDatabase(userdata, true);
}
yield Zotero.DB.queryAsync("PRAGMA foreign_keys = false");
try {
var updated = yield Zotero.DB.executeTransaction(function* (conn) {
yield Zotero.DB.queryAsync("PRAGMA defer_foreign_keys = true");
var updated = yield _updateSchema('system');
// Update custom tables if they exist so that changes are in
@ -137,6 +137,10 @@ Zotero.Schema = new function(){
return updated;
}.bind(this));
}
finally {
yield Zotero.DB.queryAsync("PRAGMA foreign_keys = true");
}
if (updated) {
// Upgrade seems to have been a success -- delete any previous backups