strongloop/loopback-component-push

Loopback-component-push doesn't work well when automigrating application,notification,installation models.

Closed this issue · 1 comments

When one add the line
require('./push')(app); to server.js and the user has configured the automigration of application,notifcation and installation models. The error pops up that the table is not available for model. This is happening because even before the model is created, the code inside push.js starts.

https://github.com/harshil93/loopback-component-push-bug-example

The above code is setup for mysql automigration and crashes.

Hi @harshil93, I think your application is not set up correctly.

Please change your dbsync boot script (link) to a callback-based one:

module.exports = function(app, cb){
    app.datasources['db'].automigrate([
      'application',
      'installation',
      'notification'
      ], function(err) {
        if(err) console.log(err);
        else console.log("Migration Done");
        cb(); // or cb(err) if you want to abort boot on error
      });
}

Then you need to rework your server code to wait until the boot process is finished (server/server.js):

boot(app, __dirname, function(err) {
  // handle err
  require('./push-demo')(app);

  // start the server if `$ node server.js`
  if (require.main === module) {
    app.start();
  }
});

See the current server template for inspiration.