Created
September 24, 2017 20:47
-
-
Save null4bl3/0b14d119b93eba6c5c9c7241310d2b6f to your computer and use it in GitHub Desktop.
Loopback autoUpdate / autoMigrate server/boot script.
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
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