-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.js
49 lines (47 loc) · 2.38 KB
/
install.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var colors = require('colors');
var settings = require('./server/config/environment');
var db = require('./server/components/database');
db.initialize('couchdb');
var userView = {views: {"all": {"map": "function(doc) {emit(null, doc)}","reduce": "_count"},"by_username": {"map": "function(doc) {emit(doc.username, doc)}","reduce": "_count"}, "by_id": {"map": "function(doc) {emit(doc._id, doc)}","reduce": "_count"}, "by_admins": {"map": "function(doc) { if(doc.admin) {emit(doc.username, doc)}}","reduce": "_count"}}};
var childListView = {views: {"all": {"map": "function(doc) {emit(null, doc)}","reduce": "_count"},"by_pid": {"map": "function(doc) {emit(doc.pid, doc)}","reduce": "_count"}}};
var teamView = {views: {"all": {"map": "function(doc) {emit(null, doc)}","reduce": "_count"},"by_name": {"map": "function(doc) {emit(doc.name, doc)}","reduce": "_count"},"by_id": {"map": "function(doc) {emit(doc._id, doc)}","reduce": "_count"}}};
db.createDB(settings.couchdb.users, function (err, body) {
if(err && err.status_code !== 412) {
return console.log(err);
}
var users = db.getUsersTable();
// Insert views to make lookup calls with.
db.insert(users, '_design/users', userView, function (err) {
// 409 is Document update conflict.
if(err && err.status_code !== 409) {
console.log('Error creating database.'.red);
return console.log(err);
}
db.createDB(settings.couchdb.childProcesses, function (err, body) {
if(err && err.status_code !== 412) {
return console.log(err);
}
var childProcesses = db.getChildTable();
// Insert view to make a lookup calls with.
db.insert(childProcesses, '_design/childProcesses', childListView, function (err, body) {
if(err && err.status_code !== 409) {
console.log('Error creating database.'.red);
return console.log(err);
}
db.createDB(settings.couchdb.teams, function (err, body) {
if(err && err.status_code !== 412) {
return console.log(err);
}
var teams = db.getTeamsTable();
db.insert(teams, '_design/teams', teamView, function (err, body) {
if(err && err.status_code !== 409) {
console.log('Error creating database.'.red);
return console.log(err);
}
console.log('DB Installation successful.'.green);
});
});
});
});
});
});