|
|
|
@ -1,8 +1,8 @@
@@ -1,8 +1,8 @@
|
|
|
|
|
#!/usr/bin/env node
|
|
|
|
|
var exec = require('child_process').exec; |
|
|
|
|
var models = require('../models'); |
|
|
|
|
var env = process.env.NODE_ENV || 'development'; |
|
|
|
|
var config = require(__dirname + '/../config/config.json')[env]; |
|
|
|
|
var env = require('../config/config.json')['env'] || 'development'; |
|
|
|
|
var config = require(__dirname + '/../config/config.json')['database'][env]; |
|
|
|
|
|
|
|
|
|
if (process.argv.length < 4) { |
|
|
|
|
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
@@ -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}"`; |
|
|
|
|
|
|
|
|
|
exec(dropUserDB, function(err,stdout,stderr) { |
|
|
|
|
console.log(stdout); |
|
|
|
|
exec(createdb, function(err,stdout,stderr) { |
|
|
|
|
if (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
process.exit(0); |
|
|
|
|
} else { |
|
|
|
|
console.log(stdout); |
|
|
|
|
exec(createUser, function(err, stdout, stderr) { |
|
|
|
|
if (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
process.exit(0); |
|
|
|
|
} else { |
|
|
|
|
console.log(stdout); |
|
|
|
|
exec(grantAccess, function(err, stdout, stderr) { |
|
|
|
|
if (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
} else { |
|
|
|
|
console.log(stdout); |
|
|
|
|
models.sequelize.sync({force: true}) |
|
|
|
|
.then(() => { |
|
|
|
|
console.log(`\nUSER (${config.username}) AND DATABASE (${config.database}) CREATED SUCCESSFULLY`); |
|
|
|
|
process.exit(0); |
|
|
|
|
}) |
|
|
|
|
.catch((err) => { |
|
|
|
|
console.log(err); |
|
|
|
|
process.exit(0); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
console.log(stdout); |
|
|
|
|
exec(createdb, function(err,stdout,stderr) { |
|
|
|
|
if (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
process.exit(0); |
|
|
|
|
} else { |
|
|
|
|
console.log(stdout); |
|
|
|
|
exec(createUser, function(err, stdout, stderr) { |
|
|
|
|
if (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
process.exit(0); |
|
|
|
|
} else { |
|
|
|
|
console.log(stdout); |
|
|
|
|
exec(grantAccess, function(err, stdout, stderr) { |
|
|
|
|
if (err) { |
|
|
|
|
console.log(err); |
|
|
|
|
} else { |
|
|
|
|
console.log(stdout); |
|
|
|
|
models.sequelize.sync({force: true}) |
|
|
|
|
.then(() => { |
|
|
|
|
console.log(`\nUSER (${config.username}) AND DATABASE (${config.database}) CREATED SUCCESSFULLY`); |
|
|
|
|
process.exit(0); |
|
|
|
|
}) |
|
|
|
|
.catch((err) => { |
|
|
|
|
console.log(err); |
|
|
|
|
process.exit(0); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|