obrand-admin-server/dbconfig.js

75 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-04-04 13:52:55 +00:00
/**
*
* User: Martin Donnelly
* Date: 2016-04-04
* Time: 14:46
*
*/
var db = require('./server/units/db-connector').dbConnection;
var dbAccount = require('./server/units/db-accounts')(db);
var exec = require('child_process').exec;
function addUsers() {
'use strict';
dbAccount.addNewAccount({
username: 'Martin ', password: 'MPReoa43', email: 'martind2000@gmail.com'
})
.then(function(data) {
console.log(data);
2016-04-04 14:03:42 +00:00
dbAccount.addNewAccount({
username: 'Default', password: 'password', email: 'm@g.com'
})
.then(function(data) {
console.log(data);
return 'DONE';
})
.catch(function(err) {
console.error(err);
return -1;
});
2016-04-04 13:52:55 +00:00
})
.catch(function(err) {
console.error(err);
2016-04-04 14:03:42 +00:00
return -1;
2016-04-04 13:52:55 +00:00
});
2016-04-04 14:03:42 +00:00
2016-04-04 13:52:55 +00:00
}
2016-04-04 14:01:42 +00:00
function prepare_db() {
exec('psql -Upostgres -d oBrand -h localhost -f ./obrand.sql', function(err) {
if (err !== null) {
console.log('exec error: ' + err);
2016-04-04 14:03:42 +00:00
return -1;
2016-04-04 14:01:42 +00:00
} else {
addUsers();
}
});
}
2016-04-04 14:10:56 +00:00
function createDB() {
'use strict';
2016-04-04 14:13:40 +00:00
exec('createdb -Upostgres -h localhost -d oBrand', function(err) {
2016-04-04 14:10:56 +00:00
if (err !== null) {
console.log('exec error: ' + err);
return -1;
} else {
prepare_db();
}
});
}
createDB();