Skip to content

Commit

Permalink
Update config/database.yml to use DATABASE_URL in production
Browse files Browse the repository at this point in the history
The previous configuration would result in the following type of error on
Heroku.

    app[web.1]: /.../connection_adapters/postgresql_adapter.rb:888:in
      `initialize': could not connect to server: No such file or directory (PG::ConnectionBad)
    app[web.1]:    Is the server running locally and accepting
    app[web.1]:    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

From
<https://github.com/rails/rails/blob/4-1-stable/activerecord/CHANGELOG.md#rails-410-april-8-2014>:

> Currently Active Record can be configured via the environment variable
> `DATABASE_URL` or by manually injecting a hash of values which is what Rails
> does, reading in `database.yml` and setting Active Record appropriately.
> Active Record expects to be able to use `DATABASE_URL` without the use of
> Rails, and we cannot rip out this functionality without deprecating.

The `DATABASE_URL` environment variable should contain all the settings now
removed from `config/database.yml`.
  • Loading branch information
Koronen committed Jan 30, 2016
1 parent 4884737 commit 9ff9d5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
7 changes: 1 addition & 6 deletions config/database.yml
Expand Up @@ -9,11 +9,6 @@ test:
database: db/stringer_test.sqlite

production:
adapter: postgresql
url: <%= ENV["DATABASE_URL"] %>
encoding: unicode
pool: 5
database: <%= ENV['STRINGER_DATABASE'] || "stringer" %>
username: <%= ENV['STRINGER_DATABASE_USERNAME'] %>
password: <%= ENV['STRINGER_DATABASE_PASSWORD'] %>
host: <%= ENV['STRINGER_DATABASE_HOST'] %>
port: <%= ENV['STRINGER_DATABASE_PORT'] %>
20 changes: 9 additions & 11 deletions docs/VPS.md
Expand Up @@ -14,11 +14,11 @@ The first step is installing some essential dependencies from your VPS's package
On CentOS after installing Postgres, I needed to run these commands, Fedora likely the same.

service postgresql initdb && service postgresql start

#### Arch Linux

pacman -S git postgresql base-devel libxml2 libxslt curl sqlite readline postgresql-libs

Here are some Arch specific instructions for setting up postgres

systemd-tmpfiles --create postgresql.conf
Expand Down Expand Up @@ -47,7 +47,7 @@ We will run stringer as it's own user for security, also we will be installing a
useradd stringer -m -s /bin/bash
su -l stringer

Always use -l switch when you switch user to your stringer user, without it your modified .bash_profile or .profile file will be ignored.
Always use -l switch when you switch user to your stringer user, without it your modified .bash_profile or .profile file will be ignored.

Install Ruby for your stringer user
===================================
Expand All @@ -69,7 +69,7 @@ We also need to install bundler which will handle Stringer's dependencies

gem install bundler
rbenv rehash

We will also need foreman to run our app

gem install foreman
Expand All @@ -87,16 +87,14 @@ Use bundler to grab and build Stringer's dependencies
bundle install
rbenv rehash

Stringer uses environment variables to determine information about your database, edit these values to reflect your database and the password you chose earlier
Stringer uses environment variables to configure the application. Edit these values to reflect your settings.

echo 'export STRINGER_DATABASE="stringer_live"' >> $HOME/.bash_profile
echo 'export STRINGER_DATABASE_USERNAME="stringer"' >> $HOME/.bash_profile
echo 'export STRINGER_DATABASE_PASSWORD="EDIT_ME"' >> $HOME/.bash_profile
echo 'export DATABASE_URL="postgres://stringer:EDIT_ME@localhost/stringer_live"' >> $HOME/.bash_profile
echo 'export RACK_ENV="production"' >> $HOME/.bash_profile
echo "export SECRET_TOKEN=`openssl rand -hex 20`" >> $HOME/.bash_profile
source ~/.bash_profile
Tell stringer to run the database in production mode, using the postgres database you created earlier.

Tell stringer to run the database in production mode, using the `postgres` database you created earlier.

cd $HOME/stringer
rake db:migrate RACK_ENV=production
Expand All @@ -105,7 +103,7 @@ Run the application:

foreman start

Set up a cron job to parse the rss feeds.
Set up a cron job to parse the rss feeds.

crontab -e

Expand Down

0 comments on commit 9ff9d5a

Please sign in to comment.