From 68c62d41d2b77f4aa9dbb177e47acf6caa369074 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Sun, 2 Aug 2015 20:32:51 -0400 Subject: let's see if we can get Heroku to create the schema for us --- app.json | 5 ++++- db/bootstrap.js | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 db/bootstrap.js diff --git a/app.json b/app.json index 4d1b3f2..10cc28d 100644 --- a/app.json +++ b/app.json @@ -1,5 +1,8 @@ { "addons": [ "heroku-postgresql:hobby-dev" - ] + ], + "scripts": { + "postdeploy": "node db/bootstrap.js" + } } 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(); + }); + }); +}); -- cgit v1.2.3