Skip to content

Instantly share code, notes, and snippets.

@null4bl3
Created September 24, 2017 20:47
Show Gist options
  • Save null4bl3/0b14d119b93eba6c5c9c7241310d2b6f to your computer and use it in GitHub Desktop.
Save null4bl3/0b14d119b93eba6c5c9c7241310d2b6f to your computer and use it in GitHub Desktop.
Loopback autoUpdate / autoMigrate server/boot script.
module.exports = function(app) {
var path = require('path');
var models = require(path.resolve(__dirname, '../model-config.json'));
var datasources = require(path.resolve(__dirname, '../datasources.json'));
function autoUpdateAll(){
Object.keys(models).forEach(function(key) {
if (typeof models[key].dataSource != 'undefined') {
if (typeof datasources[models[key].dataSource] != 'undefined') {
app.dataSources[models[key].dataSource].autoupdate(key, function (err) {
if (err) throw err;
console.log('Model ' + key + ' updated');
});
}
}
});
}
function autoMigrateAll(){
Object.keys(models).forEach(function(key) {
if (typeof models[key].dataSource != 'undefined') {
if (typeof datasources[models[key].dataSource] != 'undefined') {
app.dataSources[models[key].dataSource].automigrate(key, function (err) {
if (err) throw err;
console.log('Model ' + key + ' migrated');
});
}
}
});
}
//TODO: change to autoUpdateAll when ready for CI deployment to production
// autoMigrateAll();
autoUpdateAll();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment