You are in flow developing on your local database and you decide to upload everything to heroku and share it with the world.
How do you configure your production database?
Its easier than you think. Lets assume you have already set up your site. (link)
If you used the sequelize init command, you will have a file
db/models/index.js that looks like this
sequelize database will initialize with the usual
database, username password, etc but in the special case that your config has
use_env_variable, sequelize will recognize that an environment variable (usually representing a URI) can be used in place of the usual credentials.
What is your
After you run
heroku addon create ... a new environment variable will be created at your heroku application
Find this in your heroku settings or running
$ heroku config
You can access this with
process.env.DATABASE_URL in any of your
node.js code (on production). Your local machine will have different environment variables set.
Step 1: Set
But set it to what? Set it what heroku designates as your database url,
You may need to migrate your database if you aren’t using
Step 2: Migrate your database
Error: no pg_hba.conf entry for host…, SSL OFF
you need to set TWO attributes to specify
Error: The server does not support SSL connections
So tried to migrate your empty production database by setting the correct environment variables for the command and running
$ NODE_ENV=production DATABASEURL=<db_url> sequelize db:migrate
How do you set up your local machine to support SSL?? You could get a certificate and configure your sequelize config to use that BUT theres an easier way.
Simply run the command in the heroku environment
$ heroku run ./node_modules/.bin/sequelize db:migrate --debug