diff options
author | Ben Burwell <ben@benburwell.com> | 2015-08-02 20:47:51 -0400 |
---|---|---|
committer | Ben Burwell <ben@benburwell.com> | 2015-08-02 20:47:51 -0400 |
commit | 52aeca23f6c9a86afbaec278bc2fcda0993e3d00 (patch) | |
tree | 07ae26b03b94058e556ddbdc249e38f6b31a4b22 /db/bootstrap.js | |
parent | fe4c8335f24b191093cfa47d099cc85ebb62585d (diff) | |
parent | ac0e595a531e212e4885633eb043760bcc5d4946 (diff) |
Merge pull request #5 from benburwell/fix-pg-error
Hopefully this fixes weird PG errors
Diffstat (limited to 'db/bootstrap.js')
-rw-r--r-- | db/bootstrap.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/db/bootstrap.js b/db/bootstrap.js new file mode 100644 index 0000000..009211f --- /dev/null +++ b/db/bootstrap.js @@ -0,0 +1,23 @@ +var pg = require('pg'); +var fs = require('fs'); + +pg.connect(process.env.DATABASE_URL, function(err, client, done) { + if (err) { + return console.error('Unable to connect to datbase', err); + } + + fs.readFile('schema.sql', function(err, sql) { + if (err) { + return console.error('Unable to read SQL file', err); + } + + client.query(sql, function(err) { + if (err) { + return console.error('Error running SQL query', err); + } + + console.log('Database created'); + done(); + }); + }); +}); |