I have a small problem, this script works perfectly, with one problem, the "runTenant" method is not returning a promise (that needs resolving from "all()".
This code:
Promise.resolve(runTenant(latest)).then(function() {
  end();
});
Calls this code:
function runTenant(cb) {
  return new Promise(function() {
    //global var
    if (!Tenant) {
      loadCoreModels();
      Tenant = bookshelf.core.bs.model('Tenant');
    }
    new Tenant().fetchAll()
      .then(function(tenants) {
        if (tenants.models.length == 0) {
          return;
        } else {
          async.eachSeries(tenants.models, function(tenant, next) {
            var account = tenant.attributes;
            Promise.resolve(db_tenant.config(account)).then(function(knex_tenant_config) {
              if (knex_tenant_config) {
                db_tenant.invalidateRequireCacheForFile('knex');
                var knex_tenant = require('knex')(knex_tenant_config);
                var knex_pending = cb(knex_tenant);
                Promise.resolve(knex_pending).then(function() {
                  next(null, null);
                });
              } else {
                next(null, null);
              }
            });
          });
        };
      });
  });
}
The code from runTenant is working correctly however it stalls and does not proceed to "end()" because the promise from "runTenant(latest)" isn't being resolved.
As if it weren't apparent, I am horrible at promises. Still working on getting my head around them.
Many thanks for any help/direction!
 
     
     
     
    