forked from xgrommx/vizor-create
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
47 lines (40 loc) · 1012 Bytes
/
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
var r = require('rethinkdb')
var _rethinkConnection
function setupRethinkDatabase() {
var dbName = process.env.RETHINKDB_NAME || 'vizor'
var tableName = 'editlog'
return r.connect({
host: process.env.RETHINKDB_HOST || 'localhost',
port: 28015,
db: dbName
})
.then(function(conn) {
_rethinkConnection = conn
return r.dbList().run(conn)
.then(function(dbList) {
if (dbList.indexOf(dbName) === -1)
return r.dbCreate(dbName).run(conn)
})
.then(function() {
return r.db(dbName).tableList().run(conn)
.then(function(list) {
if (list.indexOf(tableName) === -1) {
return r.db(dbName)
.tableCreate('editlog')
.run(conn)
}
})
}).then(function() {
_rethinkConnection.close()
})
})
.error(function errHandler(err) {
throw err;
})
}
exports.setupRethinkDatabase = setupRethinkDatabase
if (require.main === module) {
var bundleEditorScripts = require('./editorBundler').bundleEditorScripts
setupRethinkDatabase()
.then(bundleEditorScripts)
}