Created
January 17, 2015 06:43
-
-
Save mirhec/c273feb045b29dbca972 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
## Check if database exists. If it does not exist | |
## create it and create all tables and indices. | |
## The names of the Db, tables and indices are | |
## specified in config.coffee | |
### | |
createDbIfNotExists: () -> | |
r.connect config.rethinkdb, (err, connection) => | |
if err | |
console.log "Could not open a connection to initialize the database" | |
console.log err.message | |
process.exit 1 | |
# save connection object | |
@conn = connection | |
# check if a database exists | |
r.dbList().run @conn, (err, result) => | |
# check length of result | |
if result.length == 0 | |
# create db | |
@createDb () => | |
# create all tables | |
for table in config.rethinkdb.tables | |
@createTable table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment