This repository has been archived by the owner on Sep 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
61 lines (55 loc) · 1.61 KB
/
setup.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
50
51
52
53
54
55
56
57
58
59
60
61
// sets up the DBs. ONLY RUN ONCE
// depends
var r = require('rethinkdb'),
config = require('./config'),
l = require('./log'),
db = require('./db');
var i = 0,
j = 0;
// sets up server
db.rql(function(conn) {
r.dbCreate(config.rethinkdb.db)
.run(conn, function(err, result) {
if (err) {
l.setupInfo('Potential Error', err);
} else {
l.setupSuccess(result, 'DB: ' + config.rethinkdb.db);
}
for (var table in config.rethinkdb.tables) {
setUpTable(table, conn);
}
});
});
function setUpTable (tbl, conn) {
r.tableCreate(tbl)
.run(conn, function(err, result) {
if (err) {
l.setupInfo('Potential Error', err);
} else {
l.setupSuccess(result, 'TBL: ' + tbl);
}
for (var index in config.rethinkdb.tables[tbl]) {
setUpIndex(index, conn, tbl);
}
});
}
function setUpIndex (inx, conn, tbl) {
r.table(tbl)
.indexCreate(config.rethinkdb.tables[tbl][inx])
.run(conn, function(err, result) {
if (err) {
l.setupInfo('Potential Error', err);
} else {
l.setupSuccess(result, "INX: " + config.rethinkdb.tables[tbl][inx]);
}
j++;
if (j === i) {
throw l.info("Rethinkdb configured successfully! Killing node...");
}
});
}
for (var table in config.rethinkdb.tables) {
for (var index in config.rethinkdb.tables[table]) {
i++;
}
}