Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorsosa/1b1d4056ace79df0ffb00fe08905af9d to your computer and use it in GitHub Desktop.
Save victorsosa/1b1d4056ace79df0ffb00fe08905af9d to your computer and use it in GitHub Desktop.
Loopback boot scripts to update the table based on json model definition, the name of the table should be speci
var glob = require('glob');
var path = require('path');
module.exports = function(app) {
var ds = app.dataSources['automailer-db']
var files = glob.sync(path.join(__dirname, '..', '..', '/common/models/*.json'))
files.forEach(function(file) {
var modelDefinition = require(file)
ds.createModel(modelDefinition.name, modelDefinition.properties, modelDefinition.options);
ds.autoupdate(modelDefinition.name, function(err, result) {
ds.discoverModelProperties(modelDefinition.options.postgresql.table, function (err, props) {
console.log('Schema ' + modelDefinition.name + ' is updated');
// console.log(props)
});
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment