Created
January 1, 2018 06:11
-
-
Save sofyan-ahmad/4959ae06478067ca1d0ee4870f32f81a to your computer and use it in GitHub Desktop.
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 path = require('path'); | |
var lodash = require('lodash'); | |
var app = require(path.resolve(__dirname, '../server/server')); | |
var models = require(path.resolve( | |
__dirname, | |
'../server/model-config.local.js' | |
)); | |
function autoMigrateAll(dataSourceName) { | |
var ds = app.datasources[dataSourceName]; | |
console.warn('----------------------------------------------'); | |
console.warn('[WARNING] This process will drop all your data'); | |
console.warn('----------------------------------------------'); | |
const tables = []; | |
lodash.forEach(models, function(val, key) { | |
if (val.dataSource === dataSourceName && !val.noMigration) tables.push(key); | |
}); | |
console.log('Migrating database with tables ', tables); | |
ds.automigrate(tables, function(err) { | |
if (err) throw err; | |
ds.disconnect(); | |
console.log('Migration done, happy coding :)'); | |
process.exit(); | |
}); | |
} | |
// migrate only datasource with name 'mainDS' | |
autoMigrateAll('mainDS'); |
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 path = require('path'); | |
var lodash = require('lodash'); | |
var app = require(path.resolve(__dirname, '../server/server')); | |
var models = require(path.resolve( | |
__dirname, | |
'../server/model-config.local.js' | |
)); | |
function autoUpdateAll(dataSourceName) { | |
var ds = app.datasources[dataSourceName]; | |
console.log('Updating database'); | |
const tables = []; | |
lodash.forEach(models, function(val, key) { | |
if (val.dataSource === dataSourceName && !val.noMigration) tables.push(key); | |
}); | |
console.log('Updating database with tables ', tables); | |
ds.autoupdate(tables, function(err) { | |
if (err) throw err; | |
ds.disconnect(); | |
console.log('Update done, happy coding :)'); | |
process.exit(); | |
}); | |
} | |
// migrate only datasource with name 'mainDS' | |
autoUpdateAll('mainDS'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment