app.js
/**
 * update_database
 * 
 * Updates the database to the current build number. First call it returns
 * a callback and begins recursively applying updates. The promise is 
 * resolved on successful application of all updates and rejected if 
 * any update fails.
 */


Updates the database to the current build number. First call it returns
a callback and begins recursively applying updates. The promise is
resolved on successful application of all updates and rejected if
any update fails.
Updates the database to the current build number . First call it returns a callback and begins recursively applying updates . The promise is resolved on successful application of all updates and rejected if any update fails .
function update_database(build = 0) {
  if (build == 0) {
    return new Promise ((resolve, reject) => {
      db_get("SELECT value FROM settings WHERE key='build'").then((row) => {
        update_database(parseInt(row.value), resolve, reject);
      });
    });
  }
  var resolve = arguments[1];
  var reject = arguments[2];
  if (build > UPDATES.length) {
    return resolve();
  }
  C.log('UPDATING to build ', build);
  UPDATES[build-1]().then(() => {
    update_database(build+1, resolve, reject);
  }).catch(err => {
    reject(err);
  });
}
function update_database ( build = 0 ) { if ( build == 0 ) { return new Promise ( ( resolve , reject ) => { db_get ( "SELECT value FROM settings WHERE key='build'" ) . then ( ( row ) => { update_database ( parseInt ( row . value ) , resolve , reject ) ; } ) ; } ) ; } var resolve = arguments [ 1 ] ; var reject = arguments [ 2 ] ; if ( build > UPDATES . length ) { return resolve ( ) ; } C . log ( 'UPDATING to build ' , build ) ; UPDATES [ build - 1 ] ( ) . then ( ( ) => { update_database ( build + 1 , resolve , reject ) ; } ) . catch ( err => { reject ( err ) ; } ) ; }
update_database
update_database