Forked from indrasantosa/loopback-auto-update-structure.js
Created
January 26, 2018 15:10
-
-
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
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