I'm most of the way there, has anyone gotten it to succesfully work? I only have the database working locally, after I git push heroku master the connection to the database fails.
1 Answer
Add 'Heroku Postgres' either through the Heroku CLI or under your project's Resources tab. It should also give you a
DATABASE_URLvariable which you need for later.Add pg module from Heroku. See the documentation here.
$ npm install --save --save-exact pgThen, on the server, use the
DATABASE_URLwe just got.const client = new Client({ connectionString: process.env.DATABASE_URL, ssl: true, }); client.connect();Put
"use_env_variable": "DATABASE_URL"on theconfig.jsonfile under "production". Should look like"production": { "use_env_variable": "DATABASE_URL" ... }Run migrations on Heroku. An option if you want to use sequelize-cli is:
$ npm install sequelize-cli --save $ heroku run sequelize db:migrate
And it should work.