commit 7e30afb2a56b8c4296548fd6782619ae0719c612
parent 56d937214611642f9ff176ea99b9c925ea2386ea
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 13 Jan 2017 21:16:47 -0500
Use coroutine() for Zotero.Schema::_updateSchema()
Diffstat:
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js
@@ -1418,26 +1418,24 @@ Zotero.Schema = new function(){
}
- function _updateSchema(schema){
- return Zotero.Promise.all([Zotero.Schema.getDBVersion(schema), _getSchemaSQLVersion(schema)])
- .spread(function (dbVersion, schemaVersion) {
- if (dbVersion == schemaVersion) {
- return false;
- }
- else if (dbVersion < schemaVersion) {
- return _getSchemaSQL(schema)
- .then(function (sql) {
- return Zotero.DB.executeSQLFile(sql);
- })
- .then(function () {
- return _updateDBVersion(schema, schemaVersion);
- });
- }
-
+ /**
+ * Requires a transaction
+ */
+ var _updateSchema = Zotero.Promise.coroutine(function* (schema) {
+ var [dbVersion, schemaVersion] = yield Zotero.Promise.all(
+ [Zotero.Schema.getDBVersion(schema), _getSchemaSQLVersion(schema)]
+ );
+ if (dbVersion == schemaVersion) {
+ return false;
+ }
+ if (dbVersion > schemaVersion) {
throw new Error("Zotero '" + schema + "' DB version (" + dbVersion
+ ") is newer than SQL file (" + schemaVersion + ")");
- });
- }
+ }
+ let sql = yield _getSchemaSQL(schema);
+ yield Zotero.DB.executeSQLFile(sql);
+ return _updateDBVersion(schema, schemaVersion);
+ });
var _updateCompatibility = Zotero.Promise.coroutine(function* (version) {