Skip to content

Instantly share code, notes, and snippets.

@indrasantosa
Created April 21, 2017 03:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save indrasantosa/4ca8cc97770e9e3ea6cba58394ee0e46 to your computer and use it in GitHub Desktop.
Save indrasantosa/4ca8cc97770e9e3ea6cba58394ee0e46 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