Created
April 21, 2017 03:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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