Objectives
By the end of this breakout, you will be able to:
- Set up an application on heroku
- Provision a postgres DB on Heroku
- Run knex commands to create the schema and seed a production database
- Install the herkou CLI
brew install heroku
- Signup and login to heroku
heroku login
- Create a heroku app
heroku create
- Push to heroku
git push heroku master
- Open the URL from the command line
heroku open
- View heroku logs
heroku logs --tail
- Add postgres addon
heroku addons:create heroku-postgresql:hobby-dev
- Add production connection to knex
- Add a production enviornment to the knex.js file in your root directory. The connection should be set to process.env.DATABASE_URL
- Look in your db/knex.js file and ensure your connection variable is set to
process.env.NODE_ENV || developement
- Download the npm package dotenv
npm install dotenv
- Require the pacakge in your knexfile.js
require('dotenv').config()
- Make a .env file
touch .env
-
Add your .env file to your .gitignore file
-
Add your database url to your .env file
- Find your app on heroku > settings > config variables
DATABASE_URL=39ualdkfj029iepaeuhfglakwjhlfkajhdsp9f8p34k
heroku run knex migrate:latest
- Use psql to examine tables and data on the production DB
heroku pg:psql
- Run seed on production DB
heroku run knex seed:run