1 - Create an account on heroku
2 - Install heroku CLI, authenticate
npm install -g heroku
heroku login
3 - create heroku app
heroku create <your-app-name>
4 - intall postgres add on for app
https://elements.heroku.com/addons/heroku-postgresql
heroku addons:create heroku-postgresql:hobby-dev
5 - in package.json
add postgress to dependencies
npm i --save pg
5 - in knexfile.js
, add + export production config
// ..... after dev config .....
const prodConfig = Object.assign(
{},
devConfig,
{ client: 'pg', connection: process.env.DATABASE_URL}
)
module.exports = {
development: devConfig,
production: prodConfig
}
6 - in server.js
, configure dbConnectionConfig object for knex
const dbConfigObj = require('./knexfile')
// .....
const app = express()
let dbConnectionConfig
switch (process.env.NODE_ENV){
case 'production':
dbConnectionConfig = dbConfigObj.production :
break;
default:
dbConnectionConfig = dbConfigObj.development
}
const appDb = connectToDb(dbConnectionConfig)
Model.knex(appDb)
7 - commit your work (on master branch)
8 - push to heroku
git push heroku master
9 - run migrations
heroku run knex migrate:latest
10 - run seeds
heroku run knex seed:run
@bbrizzi
Try calling knex.migrate.latest directly in your db.js, like: