|
|
@ -1,8 +1,8 @@ |
|
|
|
#!/usr/bin/env node
|
|
|
|
#!/usr/bin/env node
|
|
|
|
var exec = require('child_process').exec; |
|
|
|
var exec = require('child_process').exec; |
|
|
|
var models = require('../models'); |
|
|
|
var models = require('../models'); |
|
|
|
var env = process.env.NODE_ENV || 'development'; |
|
|
|
var env = require('../config/config.json')['env'] || 'development'; |
|
|
|
var config = require(__dirname + '/../config/config.json')[env]; |
|
|
|
var config = require(__dirname + '/../config/config.json')['database'][env]; |
|
|
|
|
|
|
|
|
|
|
|
if (process.argv.length < 4) { |
|
|
|
if (process.argv.length < 4) { |
|
|
|
console.log('Provide root user name and password for mysql'); |
|
|
|
console.log('Provide root user name and password for mysql'); |
|
|
@ -15,37 +15,37 @@ const createUser = `mysql -u${process.argv[2]} -p${process.argv[3]} -e "create u |
|
|
|
const grantAccess = `mysql -u${process.argv[2]} -p${process.argv[3]} -e "grant all on ${config.database}.* to ${config.username}"`; |
|
|
|
const grantAccess = `mysql -u${process.argv[2]} -p${process.argv[3]} -e "grant all on ${config.database}.* to ${config.username}"`; |
|
|
|
|
|
|
|
|
|
|
|
exec(dropUserDB, function(err,stdout,stderr) { |
|
|
|
exec(dropUserDB, function(err,stdout,stderr) { |
|
|
|
console.log(stdout); |
|
|
|
console.log(stdout); |
|
|
|
exec(createdb, function(err,stdout,stderr) { |
|
|
|
exec(createdb, function(err,stdout,stderr) { |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
console.log(err); |
|
|
|
console.log(err); |
|
|
|
process.exit(0); |
|
|
|
process.exit(0); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log(stdout); |
|
|
|
console.log(stdout); |
|
|
|
exec(createUser, function(err, stdout, stderr) { |
|
|
|
exec(createUser, function(err, stdout, stderr) { |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
console.log(err); |
|
|
|
console.log(err); |
|
|
|
process.exit(0); |
|
|
|
process.exit(0); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log(stdout); |
|
|
|
console.log(stdout); |
|
|
|
exec(grantAccess, function(err, stdout, stderr) { |
|
|
|
exec(grantAccess, function(err, stdout, stderr) { |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
console.log(err); |
|
|
|
console.log(err); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log(stdout); |
|
|
|
console.log(stdout); |
|
|
|
models.sequelize.sync({force: true}) |
|
|
|
models.sequelize.sync({force: true}) |
|
|
|
.then(() => { |
|
|
|
.then(() => { |
|
|
|
console.log(`\nUSER (${config.username}) AND DATABASE (${config.database}) CREATED SUCCESSFULLY`); |
|
|
|
console.log(`\nUSER (${config.username}) AND DATABASE (${config.database}) CREATED SUCCESSFULLY`); |
|
|
|
process.exit(0); |
|
|
|
process.exit(0); |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((err) => { |
|
|
|
.catch((err) => { |
|
|
|
console.log(err); |
|
|
|
console.log(err); |
|
|
|
process.exit(0); |
|
|
|
process.exit(0); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|