loopbackio / loopback-connector-cloudant

LoopBack Connector for IBM Cloudant
Other
19 stars 21 forks source link

automigration bug -- migration not done before boot script runs #94

Closed jannyHou closed 7 years ago

jannyHou commented 7 years ago

Reproduce:

Investigation: setTimeout in boot script like the following code, give cloudant enough time to migrate model before creating user instance, problem solved.

'use strict';

module.exports = function(server) {
  var User = server.models.User;

  var doCreate = function() {
    User.create({username: 'John', email: 'john@doe.com', password: 'opensesame'}, function(err, users) {
      if (err) console.log(err);
      console.log(users);
    });
  };
  setTimeout(doCreate, 5000);
};

Reason When create a new user, in validation function(juggler/lib/validation.js), it checks uniqueness first, therefore calls find(), which returns 500 error due to model migration not done

jannyHou commented 7 years ago

Fixed in PR https://github.com/strongloop/loopback-connector-cloudant/pull/102

Now user need to run cloudantDS.automigrate() to migrate models.