Created
May 12, 2019 17:06
-
-
Save verdi327/a15cb0036dec67efea35c3dac59d2ef4 to your computer and use it in GitHub Desktop.
Setting up Postgres on Heroku
This file contains hidden or 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
Create Heroku App | |
-heroku create | |
Rename Heroku App | |
-heroku apps:rename <new-name> | |
Create Heroku Postgres DB | |
-heroku addons:create heroku-postgresql:hobby-dev | |
Get DB Credentials | |
-heroku pg:credentials:url | |
Update .env File | |
-PROD_MIGRATION_DB_HOST=<host-name> | |
-PROD_MIGRATION_DB_PORT=<port> | |
-PROD_MIGRATION_DB_NAME=<db-name> | |
-PROD_MIGRATION_DB_USER=<db-user> | |
-PROD_MIGRATION_DB_PASS=<db-password> | |
Add Prod Postgrator Config (if not already created) | |
require('dotenv').config(); | |
module.exports = { | |
"migrationDirectory": "migrations", | |
"driver": "pg", | |
"host": process.env.PROD_MIGRATION_DB_HOST, | |
"port": process.env.PROD_MIGRATION_DB_PORT, | |
"database": process.env.PROD_MIGRATION_DB_NAME, | |
"username": process.env.PROD_MIGRATION_DB_USER, | |
"password": process.env.PROD_MIGRATION_DB_PASS, | |
"ssl": true | |
} | |
Update NPM Scripts | |
"migrate-production": "postgrator --config postgrator-production-config.js", | |
"predeploy": "npm audit && npm run migrate-production" | |
Extra Credit | |
-Add dotenv package to create-react-app | |
-Create .env file | |
-prefix all env vars with REACT_APP | |
-require('dotenv').config() inside of Index.js |
Yea, I have a function inside of my config.js file that sets the DB_URL based of the NODE_ENV
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
heyo,
Maybe you didnt want to add it, or solved it a different way, but adding something like
DB_URL: process.env.DATABASE_URL to the server-side config file
or using it directly in the server.js file, to connect o knex